private void rest() {
   try {
     Thread.sleep(100); // do nothing for 1000 miliseconds (1 second)
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Example #2
0
 protected void runEcho() {
   Scanner socketScanner = null;
   String newLine;
   try {
     socketScanner = new Scanner(socket.getInputStream());
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   while (true) {
     try {
       Thread.sleep(CLERK_DELAY_MS);
     } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     if (socket.isClosed()) return;
     if (socketScanner.hasNextLine()) {
       newLine = socketScanner.nextLine() + END_OF_LINE;
       System.out.println("echoing: " + newLine);
       try {
         socket.getOutputStream().write(newLine.getBytes(encoding));
       } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }
   }
 }
Example #3
0
  // ----This function getting nodes from mongo's collection tree_nodes----
  // ---------the function insert nodes to neo4j and deletes it from mongo-----------
  // ----------------------------------------------------------------------------------------
  public void update_tree() {
    while (true) {
      DBObject obj = new BasicDBObject();
      obj.put("in_process", 0); // when other thread processing, 'in_process'=1
      DBCursor cursor = this.colltree.find(obj); // find only documents not in use of other thread
      // log4j.info(cursor.count() + " documents to process in collection tree nodes");
      if (!cursor.hasNext()) { // no documents to process
        try {
          log4j.info("there is no nodes to process at the moment, going to sleep for 10 seconds");
          Thread.currentThread();
          Thread.sleep(1000 * 10);
          log4j.info("update_tree woke up, continues");
        } catch (InterruptedException e) {
          log4j.error("InterruptedException caught, at update_all_tweets");
          e.printStackTrace();
          log4j.error(e);
        }
      } else // there are documents to process
      {
        try {
          while (cursor.hasNext()) {
            DBObject tr = cursor.next();
            try {
              String parent = tr.get("parent").toString();
              String[] sons = tr.get("son").toString().split(","); // make array of sons
              neo4j.addNode(
                  parent, sons, this.log4j); // create nodes and relationships if not exists
              this.colltree.remove(tr); // remove document from collection

            } catch (ConcurrentModificationException e) {
              // log4j.error(e);
              log4j.warn(e);
            }
          }
        } catch (MongoException e) {
          log4j.error(e);
        }
      }
    }
  }