// Do some simple concurrent testing
  public void testConcurrentSimple() throws InterruptedException {
    final NonBlockingIdentityHashMap<String, String> nbhm =
        new NonBlockingIdentityHashMap<String, String>();
    final String[] keys = new String[20000];
    for (int i = 0; i < 20000; i++) keys[i] = "k" + i;

    // In 2 threads, add & remove even & odd elements concurrently
    Thread t1 =
        new Thread() {
          public void run() {
            work_helper(nbhm, "T1", 1, keys);
          }
        };
    t1.start();
    work_helper(nbhm, "T0", 0, keys);
    t1.join();

    // In the end, all members should be removed
    StringBuffer buf = new StringBuffer();
    buf.append("Should be emptyset but has these elements: {");
    boolean found = false;
    for (String x : nbhm.keySet()) {
      buf.append(" ").append(x);
      found = true;
    }
    if (found) System.out.println(buf + " }");
    assertThat("concurrent size=0", nbhm.size(), is(0));
    for (String x : nbhm.keySet()) {
      assertTrue("No elements so never get here", false);
    }
  }
Example #2
0
 /** Print message with exception stack trace */
 protected void print(String msg, Throwable e) {
   StringBuffer sb = new StringBuffer();
   sb.append(getName());
   sb.append(": ");
   sb.append(msg);
   sb.append("\n");
   if (e != null) {
     sb.append(StringUtil.stackTraceString(e));
   }
   System.out.print(sb.toString());
 }
 @Override
 public String toString() {
   final StringBuffer sb = new StringBuffer();
   sb.append("Employee");
   sb.append("{name='").append(name).append('\'');
   sb.append(", age=").append(age);
   sb.append(", active=").append(active);
   sb.append(", salary=").append(salary);
   sb.append('}');
   return sb.toString();
 }
  protected void setupScoreBoardValues() {
    new ScoreBoardValue(
        "%sbto", "ScoreBoard Timeout Owner", getScoreBoard(), ScoreBoard.EVENT_TIMEOUT_OWNER) {
      public String getValue() {
        return getScoreBoard().getTimeoutOwner();
      }
    };
    new ScoreBoardValue(
        "%sbip", "ScoreBoard Is In Period", getScoreBoard(), ScoreBoard.EVENT_IN_PERIOD) {
      public String getValue() {
        return String.valueOf(getScoreBoard().isInPeriod());
      }
    };
    new ScoreBoardValue(
        "%sbio", "ScoreBoard Is In Overtime", getScoreBoard(), ScoreBoard.EVENT_IN_OVERTIME) {
      public String getValue() {
        return String.valueOf(getScoreBoard().isInOvertime());
      }
    };
    new ScoreBoardValue(
        "%sbos", "ScoreBoard Is Score Official", getScoreBoard(), ScoreBoard.EVENT_OFFICIAL_SCORE) {
      public String getValue() {
        return String.valueOf(getScoreBoard().isOfficialScore());
      }
    };

    setupTeamValues("1", Team.ID_1);
    setupTeamValues("2", Team.ID_2);
    setupClockValues("p", Clock.ID_PERIOD);
    setupClockValues("j", Clock.ID_JAM);
    setupClockValues("l", Clock.ID_LINEUP);
    setupClockValues("t", Clock.ID_TIMEOUT);
    setupClockValues("i", Clock.ID_INTERMISSION);

    StringBuffer patternBuffer = new StringBuffer();
    Iterator<String> patterns = scoreBoardValues.keySet().iterator();
    while (patterns.hasNext()) patternBuffer.append(patterns.next() + "|");
    String specifiersRegex = patternBuffer.toString().replaceAll("[|]$", "");
    formatPattern = Pattern.compile(specifiersRegex);
    eventPattern = Pattern.compile("^\\s*(" + specifiersRegex + ")");
    conditionPattern =
        Pattern.compile("(" + specifiersRegex + ")(?:(" + comparatorRegex + ")(\\S+))?");
  }
Example #5
0
  private void execute(String[] process_command) {

    this.running = true;
    // ProcessBuilder pb = new ProcessBuilder("C:\\Archivos de programa\\python2.5\\python",
    // "C:\\Archivos de programa\\python2.5\\test.py");
    // ProcessBuilder pb = new ProcessBuilder(Executables.PYTHON_EXEC, "C:\\Archivos de
    // programa\\python2.5\\test.py", "--parameter2", "--parameter3", "--parameter4=\\\"C:\\Archivos
    // de programa\\python2.5\\test.py\\\"");
    // System.err.println("Executing "+process_command);
    StringBuffer str = new StringBuffer();
    for (int i = 0; i < process_command.length; i++) {
      str.append(process_command[i]);
      // str.append("\n");
    }
    System.err.println("Executing " + str.toString());
    ProcessBuilder pb = new ProcessBuilder(process_command);
    pb.redirectErrorStream(true);

    Process p = null;
    boolean started = false;

    try {
      p = pb.start();
      BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
      started = true;
      this.current_process++;
      FileOutputStream fout = null;
      try {
        File temp = File.createTempFile("bianaParser", ".txt");
        temp.deleteOnExit();
        fout = new FileOutputStream(temp.getAbsoluteFile());
        this.window.setCurrentOutput(this.current_process, temp.getAbsolutePath());

      } catch (IOException err) {
        System.err.println("Error in creating parser out temp file");
      }
      // this.window.setCurrentOutput(this.current_process,"process_"+this.current_process);
      this.window.change_process_status(current_process, "Running");
      int c;
      while (true) {
        c = in.read();
        if (c == -1) {
          break;
        }
        fout.write(c);
      }
      fout.close();
    } catch (IOException exc) {
      exc.printStackTrace();
      if (started) p.destroy();
      return;
    }

    try {
      // System.err.println("Going to wait to finish process...");
      System.err.println(p.waitFor());
      // System.err.println("Process "+this.current_process+" really finished...");
      System.err.println("Status: " + p.exitValue());
      if (p.exitValue() == 0) {
        this.window.change_process_status(current_process, "Finished");
      } else {
        this.window.change_process_status(current_process, "Error in parsing");
      }
    } catch (InterruptedException e) {
      p.destroy();
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    // System.err.println("Going to destroy...");

    // p.destroy();
    this.running = false;
  }