public static void main(String[] args) throws Exception {
    int counter = 0;
    while (true) {
      Thread outThread = null;
      Thread errThread = null;
      try {
        // org.pitest.mutationtest.instrument.MutationTestUnit#runTestInSeperateProcessForMutationRange

        // *** start slave

        ServerSocket commSocket = new ServerSocket(0);
        int commPort = commSocket.getLocalPort();
        System.out.println("commPort = " + commPort);

        // org.pitest.mutationtest.execute.MutationTestProcess#start
        //   - org.pitest.util.CommunicationThread#start
        FutureTask<Integer> commFuture = createFuture(commSocket);
        //   - org.pitest.util.WrappingProcess#start
        //       - org.pitest.util.JavaProcess#launch
        Process slaveProcess = startSlaveProcess(commPort);
        outThread = new Thread(new ReadFromInputStream(slaveProcess.getInputStream()), "stdout");
        errThread = new Thread(new ReadFromInputStream(slaveProcess.getErrorStream()), "stderr");
        outThread.start();
        errThread.start();

        // *** wait for slave to die

        // org.pitest.mutationtest.execute.MutationTestProcess#waitToDie
        //    - org.pitest.util.CommunicationThread#waitToFinish
        System.out.println("waitToFinish");
        Integer controlReturned = commFuture.get();
        System.out.println("controlReturned = " + controlReturned);
        // NOTE: the following won't get called if commFuture.get() fails!
        //    - org.pitest.util.JavaProcess#destroy
        outThread.interrupt(); // org.pitest.util.AbstractMonitor#requestStop
        errThread.interrupt(); // org.pitest.util.AbstractMonitor#requestStop
        slaveProcess.destroy();
      } catch (Exception e) {
        e.printStackTrace(System.out);
      }

      // test: the threads should exit eventually
      outThread.join();
      errThread.join();
      counter++;
      System.out.println("try " + counter + ": stdout and stderr threads exited normally");
    }
  }
Пример #2
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
Пример #3
0
  private void obtaindate() {
    Thread th =
        new Thread() {

          @Override
          public void run() {

            for (; true; ) {
              Calendar cd = new GregorianCalendar();

              int mon = cd.get(Calendar.MONTH);
              mon++;
              int year = cd.get(Calendar.YEAR);
              int day = cd.get(Calendar.DAY_OF_MONTH);
              date_text.setText("" + day + "/" + mon + "/" + year);

              int hh = cd.get(Calendar.HOUR_OF_DAY);
              int min = cd.get(Calendar.MINUTE);
              int sec = cd.get(Calendar.SECOND);
              time_txt.setText("" + hh + ":" + min + ":" + sec);
              try {
                Thread.sleep(1000);
              } catch (InterruptedException ex) {
                Logger.getLogger(Amin.class.getName()).log(Level.SEVERE, null, ex);
              }
            }
          }
        };
    th.setDaemon(true);
    th.start();
  }
Пример #4
0
  /** Start the network listening thread. */
  void start() {
    this.running = true;

    Thread thread = new Thread(this, "IceConnector@" + hashCode());

    thread.setDaemon(true);
    thread.start();
  }
Пример #5
0
  private void RunAllQueriesBtnMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_RunAllQueriesBtnMouseClicked
    // TODO add your handling code here:

    qThread = new PBVCPluginQueryThread(this, "", queryList, owlModel);
    Thread qthr = new Thread(qThread);
    qthr.start();
  } // GEN-LAST:event_RunAllQueriesBtnMouseClicked
Пример #6
0
  public void startConsole(boolean jLine) {
    this.jLine = jLine;

    sender = new ColoredCommandSender();
    Thread thread = new ConsoleCommandThread();
    thread.setName("ConsoleCommandThread");
    thread.setDaemon(true);
    thread.start();
  }
Пример #7
0
  private void RunThisQueryBtnMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_RunThisQueryBtnMouseClicked
    // TODO add your handling code here:
    qThread =
        new PBVCPluginQueryThread(
            this, QueriesCmb.getSelectedItem().toString(), SparqlTxtArea.getText(), owlModel);
    Thread qthr = new Thread(qThread);
    qthr.start();

    RunThisQueryBtn.setEnabled(false);
  } // GEN-LAST:event_RunThisQueryBtnMouseClicked
Пример #8
0
  public void startConsole(boolean jLine) {
    this.jLine = jLine;

    sender = new ColoredCommandSender();
    Thread thread = new ConsoleCommandThread();
    thread.setName("ConsoleCommandThread");
    thread.setDaemon(true);
    thread.start();

    /*logger.removeHandler(consoleHandler);
    consoleHandler = new FancyConsoleHandler();
    consoleHandler.setFormatter(new DateOutputFormatter(CONSOLE_DATE));
    logger.addHandler(consoleHandler);*/
  }
Пример #9
0
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showSaveDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      frame.setTitle(f.getName());
      Thread saver = new FileSaver(f, editor.getDocument());
      saver.start();
    }
Пример #10
0
  /**
   * Creates and starts the {@link #sendKeepAliveMessageThread} which is to send STUN keep-alive
   * <tt>Message</tt>s to the STUN server associated with the <tt>StunCandidateHarvester</tt> of
   * this instance in order to keep the <tt>Candidate</tt>s harvested by this instance alive.
   */
  private void createSendKeepAliveMessageThread() {
    synchronized (sendKeepAliveMessageSyncRoot) {
      Thread t = new SendKeepAliveMessageThread(this);
      t.setDaemon(true);
      t.setName(getClass().getName() + ".sendKeepAliveMessageThread: " + hostCandidate);

      boolean started = false;

      sendKeepAliveMessageThread = t;
      try {
        t.start();
        started = true;
      } finally {
        if (!started && (sendKeepAliveMessageThread == t)) sendKeepAliveMessageThread = null;
      }
    }
  }
Пример #11
0
  public void postConstruct() {

    LogManager manager = LogManager.getLogManager();
    String cname = getClass().getName();

    String systemLogging =
        TranslatedConfigView.getTranslatedValue(manager.getProperty(cname + ".useSystemLogging"))
            .toString();
    // Added below 2 lines of code to avoid NPE as per the bug
    // http://java.net/jira/browse/GLASSFISH-16162
    if (systemLogging == null) return;
    if (systemLogging.equals("false")) return;

    // set up the connection
    try {
      sysLogger = new Syslog("localhost"); // for now only write to this host
    } catch (java.net.UnknownHostException e) {
      Logger.getAnonymousLogger().log(Level.SEVERE, "unknown host");
      return;
    }

    // start the Queue consummer thread.
    pump =
        new Thread() {
          public void run() {
            try {
              while (!done.isSignalled()) {
                log();
              }
            } catch (RuntimeException e) {

            }
          }
        };
    pump.start();
  }
Пример #12
0
  /**
   * @param in input stream to be used (e.g. System.in)
   * @param prompt The prompt to display to the user.
   * @return The password as entered by the user.
   */
  public static final char[] getPassword(InputStream in, String prompt) throws IOException {
    MaskingThread maskingthread = new MaskingThread(prompt);
    Thread thread = new Thread(maskingthread);
    thread.start();

    char[] lineBuffer;
    char[] buf;
    int i;

    buf = lineBuffer = new char[128];

    int room = buf.length;
    int offset = 0;
    int c;

    loop:
    while (true) {
      c = in.read();
      switch (c) {
        case -1:
        case '\n':
          break loop;

        case '\r':
          int c2 = in.read();
          if ((c2 != '\n') && (c2 != -1)) {
            if (!(in instanceof PushbackInputStream)) {
              in = new PushbackInputStream(in);
            }
            ((PushbackInputStream) in).unread(c2);
          } else {
            break loop;
          }
        default:
          if (--room < 0) {
            buf = new char[offset + 128];
            room = buf.length - offset - 1;
            System.arraycopy(lineBuffer, 0, buf, 0, offset);
            Arrays.fill(lineBuffer, ' ');
            lineBuffer = buf;
          }
          buf[offset++] = (char) c;
          break;
      }
    }
    maskingthread.stopMasking();
    System.out.print("\010");
    // Code to clear doskey on win nt/2000 - Alt+F7
    String os = System.getProperty("os.name");
    if (os != null && os.toLowerCase().startsWith("windows")) {
      try {
        java.awt.Robot robot = new java.awt.Robot();
        robot.keyPress(java.awt.event.KeyEvent.VK_ALT);
        robot.keyPress(java.awt.event.KeyEvent.VK_F7);
        robot.keyRelease(java.awt.event.KeyEvent.VK_F7);
        robot.keyRelease(java.awt.event.KeyEvent.VK_ALT);
      } catch (Exception ignore) {
        logger.warning("Could not clears command history: " + ignore);
      }
    }

    if (offset == 0) {
      return null;
    }
    char[] ret = new char[offset];
    System.arraycopy(buf, 0, ret, 0, offset);
    Arrays.fill(buf, ' ');
    return ret;
  }
Пример #13
0
  // ----This function gets the raw json from raw_data collection----
  // ---------the function separate the tweets and inserts it to all_tweets collection and calling
  // all other data processing methods-----------
  // ----------------------------------------------------------------------------------------
  public void update_all_tweets(final double num_of_slots, final double max_time_frame_hours)
      throws MongoException, ParseException {
    log4j.info("starting update_all_tweets function");
    String res = new String();
    Integer countelements = 0;
    while (true) {
      // DBCursor cursor = this.collrd.find();
      while (this.collrd.count() < 1) { // no documents to process
        try {
          log4j.info("there is no raw data at the moment, going to sleep for 10 seconds");
          Thread.currentThread();
          Thread.sleep(1000 * 10);
          log4j.info("woke up, continues");
          // cursor = this.collrd.find();
        } catch (InterruptedException e) {
          log4j.error("InterruptedException caught, at update_all_tweets");
          log4j.error(e);
        }
      }
      DBCursor cursor = this.collrd.find(); // get all documents from raw_data collection
      try {
        while (cursor.hasNext()) {
          DBObject currdoc = cursor.next();
          log4j.info("getting a document from the raw data db");
          Object results = currdoc.get("results"); // result - json array of tweets
          try {
            res = results.toString();
          } catch (NullPointerException e) {
            res = "";
          }
          Object obj = JSONValue.parse(res);
          log4j.info("making an array from the jsons tweets");
          JSONArray array = (JSONArray) obj; // make an array of tweets
          // JSONParser parser = new JSONParser();
          try {
            if (res != "") { // if there are tweets
              @SuppressWarnings("rawtypes")
              Iterator iterArray = array.iterator();
              log4j.info("iterating over array tweets");
              try {
                while (iterArray.hasNext()) {
                  Object current = iterArray.next();
                  final DBObject dbObject =
                      (DBObject) JSON.parse(current.toString()); // parse all tweet data to json
                  countelements++;
                  // System.out.println("element number" + countelements.toString());
                  dbObject.put("max_id", currdoc.get("max_id")); // add max_id to tweet data
                  dbObject.put("query", currdoc.get("query")); // add query word to tweet data
                  dbObject.put(
                      "query_time", currdoc.get("query_time")); // add query time to tweet data
                  dbObject.put("query_time_string", currdoc.get("query_time_string"));
                  dbObject.put(
                      "text",
                      "@"
                          + dbObject.get("from_user").toString()
                          + ": "
                          + dbObject.get("text").toString()); // add user_name to beginning of text
                  dbObject.put("count", 1L); // add appearance counter to tweet data
                  log4j.info("inserting tweet id: " + dbObject.get("id").toString());
                  try {
                    DBObject object = new BasicDBObject();
                    object.put(
                        "id", Long.parseLong(dbObject.get("id").toString())); // object to search
                    DBObject newobject = collat.findOne(object);
                    if (newobject != null) {
                      newobject.put(
                          "count",
                          Long.parseLong(newobject.get("count").toString())
                              + 1); // update counter if id already exists
                      collat.update(object, newobject);
                    }
                  } catch (NullPointerException e) {

                  }
                  collat.insert(dbObject);
                  // collrd.findAndRemove(currdoc);
                  // log4j.info("calling function update_search_terms");
                  // final String text = "@" + dbObject.get("from_user").toString() + ": " +
                  // dbObject.get("text").toString();

                  /*Thread t10=new Thread(new Runnable(){
                  	public void run(){
                  		UpdateTweetCounterId(Long.parseLong(dbObject.get("id").toString()));
                  	}
                  });*/

                  Thread t11 =
                      new Thread(
                          new Runnable() {
                            public void run() {
                              update_search_terms(
                                  dbObject.get("text").toString(),
                                  num_of_slots,
                                  max_time_frame_hours,
                                  dbObject.get("query").toString());
                            }
                          });

                  Thread t12 =
                      new Thread(
                          new Runnable() {
                            public void run() {
                              rate_user(
                                  Long.parseLong(dbObject.get("from_user_id").toString()),
                                  dbObject.get("from_user").toString(),
                                  max_time_frame_hours);
                              // UpdateUserRate((long)num_of_slots,slot_time_millis,Long.parseLong(dbObject.get("from_user_id").toString()) , dbObject.get("from_user").toString() ,(long)0);
                            }
                          });

                  Thread t13 =
                      new Thread(
                          new Runnable() {
                            public void run() {
                              String quer = dbObject.get("query").toString();
                              quer = quer.replaceAll("%40", "@");
                              quer = quer.replaceAll("%23", "#");
                              long id =
                                  (long)
                                      (Double.parseDouble(dbObject.get("query_time").toString())
                                          * 1000);
                              String idplus = dbObject.get("id").toString() + "," + id;
                              SearchResultId(quer, idplus);
                            }
                          });
                  // t10.start();
                  t11.start();
                  t12.start();
                  t13.start();
                  try {
                    log4j.info("Waiting for threads to finish.");
                    // t10.join();
                    t11.join();
                    t12.join();
                    t13.join();
                  } catch (InterruptedException e) {
                    log4j.error("Main thread (update_all_tweets) Interrupted");
                  }
                }
              } catch (Exception e) {
                log4j.error(e);
                e.printStackTrace();
              }
            }
          } catch (NullPointerException e) {
            log4j.error(e);
            log4j.info("NullPointerException caught, at update_all_tweets");
          }
          log4j.info("removing processed document from raw_data collection");
          try {
            this.collrd.remove(currdoc);
          } catch (Exception e) {
            log4j.debug(e);
          }
        }
      } catch (MongoException e) {
        log4j.error(e);
      }
    }
  }