Esempio n. 1
0
  /** This is synchronized to ensure that we process the queue serially. */
  private synchronized void complete(String message) {
    // This is a weird problem with writing stuff while idling. Need to investigate it more, but
    // for now just ignore it.
    if (MESSAGE_COULDNT_BE_FETCHED_REGEX.matcher(message).matches()) {
      log.warn(
          "Some messages in the batch could not be fetched for {}\n"
              + "---cmd---\n{}\n---wire---\n{}\n---end---\n",
          new Object[] {config.getUsername(), getCommandTrace(), getWireTrace()});
      errorStack.push(new Error(completions.peek(), message, wireTrace.list()));
      throw new RuntimeException(
          "Some messages in the batch could not be fetched for user " + config.getUsername());
    }

    CommandCompletion completion = completions.peek();
    if (completion == null) {
      if ("+ idling".equalsIgnoreCase(message)) {
        synchronized (idleMutex) {
          idler.idleStart();
          log.trace("IDLE entered.");
          idleAcknowledged.set(true);
        }
      } else {
        log.error("Could not find the completion for message {} (Was it ever issued?)", message);
        errorStack.push(new Error(null, "No completion found!", wireTrace.list()));
      }
      return;
    }

    if (completion.complete(message)) {
      completions.poll();
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see poke.server.ChannelQueue#shutdown(boolean)
   */
  @Override
  public void shutdown(boolean hard) {
    logger.info("server is shutting down");

    channel = null;

    if (hard) {
      // drain queues, don't allow graceful completion
      inbound.clear();
      outbound.clear();
    }

    if (iworker != null) {
      iworker.forever = false;
      if (iworker.getState() == State.BLOCKED || iworker.getState() == State.WAITING)
        iworker.interrupt();
      iworker = null;
    }

    if (oworker != null) {
      oworker.forever = false;
      if (oworker.getState() == State.BLOCKED || oworker.getState() == State.WAITING)
        oworker.interrupt();
      oworker = null;
    }
  }
 public void syncFlushPacketQueue(MCCraftPacket[] packetWrappers) {
   while (!resyncQueue.isEmpty()) {
     Packet p = resyncQueue.pollFirst();
     if (p != null) {
       syncedSendPacket(p, packetWrappers);
     }
   }
 }
Esempio n. 4
0
 @Override
 public void run() {
   while (true) {
     if (waitingOperations.size() > 0) {
       WaitingOperation wo = waitingOperations.poll();
       processOperation(wo.getOperation(), wo.getFile());
     }
   }
 }
  public static void main(String[] args) {
    if (args.length < 2) System.exit(1);
    if (args.length > 2) {
      callMainSearch(args[1]);
      System.exit(1);
    }
    try {
      Indexer indexer = new Indexer(new File(args[1]));
      IndexerPool.addIndexer(indexer);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
    String[] sfxes = {".PDF", ".pdf"};
    Collection<File> files = FileSystemUtils.getFiles(args[0], sfxes);
    LinkedList<TextExtractorRunner> extractorRunners = new LinkedList<TextExtractorRunner>();
    LinkedList<Thread> threads = new LinkedList<Thread>();
    LinkedBlockingDeque<File> queue = new LinkedBlockingDeque<File>();
    int i = 0;
    while (i++ < 8) {
      extractorRunners.add(new TextExtractorRunner(new TextExtractor(), queue));
    }

    Iterator<TextExtractorRunner> rit = extractorRunners.iterator();
    while (rit.hasNext()) {
      Thread t = new Thread(rit.next());
      threads.add(t);
      t.start();
    }

    for (File f : files) {
      queue.offer(f);
    }
    while (true) {
      if (queue.isEmpty()) {
        break;
      }
      Utility.Sleep(100);
    }

    rit = extractorRunners.iterator();
    while (rit.hasNext()) {
      rit.next().stop();
    }

    Iterator<Thread> thIt = threads.iterator();
    while (thIt.hasNext()) {
      try {
        thIt.next().join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    System.out.println("Done ....................");
  }
 private long testingLinkedBlockingDeque() {
   LinkedBlockingDeque<Object> array = new LinkedBlockingDeque<Object>();
   long start = System.currentTimeMillis();
   for (int i = 0; i < getMax(); i++) {
     array.add(i);
   }
   long end = System.currentTimeMillis();
   long time = (end - start);
   refreshTotalTime(time);
   return time;
 }
 /**
  * Gets the next table name to load off the head of the table loading queue. If the queue is
  * empty, this will block until a new table is added.
  */
 private void loadNextTable() throws InterruptedException {
   // Always get the next table from the head of the deque.
   final TTableName tblName = tableLoadingDeque_.takeFirst();
   tableLoadingSet_.remove(tblName);
   LOG.debug("Loading next table. Remaining items in queue: " + tableLoadingDeque_.size());
   try {
     // TODO: Instead of calling "getOrLoad" here we could call "loadAsync". We would
     // just need to add a mechanism for moving loaded tables into the Catalog.
     catalog_.getOrLoadTable(tblName.getDb_name(), tblName.getTable_name());
   } catch (CatalogException e) {
     // Ignore.
   }
 }
  // def send_packet(self, pk, expected_reply=(), resend=False):
  public void sendPacket(CrtpPacket packet) {
    if (mDriver != null) {
      mDriver.sendPacket(packet);

      if (packet.getExpectedReply() != null && packet.getExpectedReply().length > 0) {
        // add packet to resend queue
        if (!mResendQueue.contains(packet)) {
          mResendQueue.add(packet);
        } else {
          mLogger.warn("Packet already exists in Queue.");
        }
      }
    }
  }
 private void cleanupFinishedOperations() {
   List<Long> toClean = new ArrayList<>();
   completedOperationIds.drainTo(toClean);
   if (!toClean.isEmpty()) {
     markOperationsCompleted(toClean);
   }
 }
 public String quickMessage() {
   try {
     return messages.poll(500, TimeUnit.MICROSECONDS);
   } catch (InterruptedException e) {
     throw new RuntimeException(e);
   }
 }
 public String message() {
   try {
     return messages.poll(10, TimeUnit.SECONDS);
   } catch (InterruptedException e) {
     throw new RuntimeException(e);
   }
 }
Esempio n. 12
0
 public void matchFound(EventBean theEvent, Collection<FilterHandleCallback> allStmtMatches) {
   if (collector != null) {
     EPDataFlowEventBeanCollectorContext holder = collectorDataTL.get();
     if (holder == null) {
       holder = new EPDataFlowEventBeanCollectorContext(graphContext, submitEventBean, theEvent);
       collectorDataTL.set(holder);
     } else {
       holder.setEvent(theEvent);
     }
     collector.collect(holder);
   } else if (submitEventBean) {
     emittables.add(theEvent);
   } else {
     emittables.add(theEvent.getUnderlying());
   }
 }
Esempio n. 13
0
    public void setPV2(String url_lwfrom, String Url) {
      String isMathchUrl = matchType(Url);
      if (isMathchUrl == null) {
        return;
      }

      String tid = "";
      String pid = null;
      if ("pc".equals(isMathchUrl)) {
        String strday = ColsDefine.formatDay.format(new Date(ts * 1000));
        pid = this.fetch(false, "pc", String.valueOf(url_lwfrom), strday);
      } else {
        pid = ColsDefine.getName(Url, "refpid");
        tid = ColsDefine.getName(Url, "tid");
      }

      if (pid != null) {
        pid_type p = new pid_type();
        p.isshaoma = false;
        p.pid = pid;
        p.tid = tid;
        p.matchUrl = isMathchUrl;
        querylist.add(p);
      }
    }
Esempio n. 14
0
 @Override
 public void run() {
   System.out.printf("Client: Begin\n");
   for (int i = 0; i < 3; i++) {
     for (int j = 0; j < 5; j++) {
       StringBuilder request = new StringBuilder();
       request.append("(");
       request.append(i);
       request.append("--");
       request.append(j);
       request.append(")");
       try {
         requestList.put(request.toString());
         TimeUnit.SECONDS.sleep(2);
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
     try {
       TimeUnit.SECONDS.sleep(2);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
   System.out.printf("Client: End\n");
 }
  /**
   * THIS COMMAND CAN ONLY BE CALLED FROM streamCommands UNLESS THE nextCommand OBJECT IS
   * SYNCHRONIZED.
   *
   * <p>Returns the next command with the following priority: 1. nextCommand object if set. 2. Front
   * of the commandBuffer collection. 3. Next line in the commandStream.
   *
   * @return
   */
  private GcodeCommand getNextCommand() {
    if (nextCommand != null) {
      return nextCommand;
    } else if (!this.commandBuffer.isEmpty()) {
      nextCommand = new GcodeCommand(commandBuffer.pop());
    } else
      try {
        if (rawCommandStream != null && rawCommandStream.ready()) {
          nextCommand = new GcodeCommand(rawCommandStream.readLine());
        } else if (commandStream != null && commandStream.ready()) {
          nextCommand = commandStream.getNextCommand();
        }
      } catch (IOException ex) {
        // Fall through to null handling.
      }

    if (nextCommand != null) {
      nextCommand.setCommandNumber(getNextCommandId());
      if (nextCommand.getCommandString().endsWith("\n")) {
        nextCommand.setCommand(nextCommand.getCommandString().trim());
      }
      return nextCommand;
    }
    return null;
  }
Esempio n. 16
0
 /** Submits a single table for background (low priority) loading. */
 public void backgroundLoad(TTableName tblName) {
   // Only queue for background loading if the table doesn't already exist
   // in the table loading set.
   if (tableLoadingSet_.add(tblName)) {
     tableLoadingDeque_.offerLast(tblName);
   }
 }
Esempio n. 17
0
 /*
  * (non-Javadoc)
  *
  * @see poke.server.ChannelQueue#enqueueRequest(eye.Comm.Finger)
  */
 @Override
 public void enqueueRequest(Request req) {
   try {
     inbound.put(req);
   } catch (InterruptedException e) {
     logger.error("message not enqueued for processing", e);
   }
 }
Esempio n. 18
0
  public void sendImmediatePacket(Packet packet) {
    packet = updateActiveChunks(packet);
    if (packet == null) {
      return;
    }

    resyncQueue.addFirst(packet);
  }
 public void releaseSelf() {
   mRequestQueue.clear();
   synchronized (mSync) {
     if (mIsRunning) {
       offerFirst(REQUEST_EGL_TASK_QUIT, 0, null);
       mIsRunning = false;
     }
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see poke.server.ChannelQueue#enqueueRequest(eye.Comm.Finger)
  */
 @Override
 public void enqueueRequest(Request req, Channel notused) {
   try {
     System.out.println("Putting the req in the inbound queue");
     inbound.put(req);
   } catch (InterruptedException e) {
     logger.error("message not enqueued for processing", e);
   }
 }
Esempio n. 21
0
 // MapChunkThread sends packets to the method. All packets should pass through this method before
 // being sent to the client
 public void queueOutputPacket(Packet packet) {
   packet = updateActiveChunks(packet);
   if (packet == null) {
     return;
   }
   resyncQueue.addLast(packet);
   if (processingKick.get()) {
     this.syncFlushPacketQueue(new MCCraftPacket[256]);
   }
 }
Esempio n. 22
0
    public DataIterParse(long ts, String[] pvlog, String line) {
      this.ts = ts;
      String Url = ColsDefine.decodeString(pvlog[3]);

      String url_lwfrom = ColsDefine.getName(Url, "lwfrom");
      this.parseSaoma(url_lwfrom);
      this.setPV2(url_lwfrom, Url);

      this.curr = querylist.poll();
    }
Esempio n. 23
0
  @Override
  public void run() {

    while (true) {
      //			log.debug("Status available="+availableSlots+" used="+usedSlots+" queue="+queue.size());
      if (availableSlots.intValue() > usedSlots.intValue() && queue.size() > 0) {
        usedSlots.incrementAndGet();
        AnalysisRunner currentRun = queue.removeFirst();
        currentRun.addAnalysisListener(this);
        Thread t = new Thread(currentRun);
        t.start();
      }

      try {
        Thread.sleep(500);
      } catch (InterruptedException e) {
      }
    }
  }
 /**
  * Callback called for every packet received to check if we are waiting for an packet like this.
  * If so, then remove it from the queue.
  *
  * @param packet
  */
 private void checkReceivedPackets(CrtpPacket packet) {
   // compare received packet with expectedReplies in resend queue
   for (CrtpPacket resendQueuePacket : mResendQueue) {
     if (isPacketMatchingExpectedReply(resendQueuePacket, packet)) {
       mResendQueue.remove(resendQueuePacket);
       mLogger.debug("QUEUE REMOVE: " + resendQueuePacket);
       break;
     }
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see poke.server.ChannelQueue#enqueueResponse(eye.Comm.Response)
   */
  @Override
  public void enqueueResponse(Request reply, Channel notused) {
    if (reply == null) return;

    try {
      outbound.put(reply);
    } catch (InterruptedException e) {
      logger.error("message not enqueued for reply", e);
    }
  }
Esempio n. 26
0
 private void disconnectAbnormally(String message) {
   try {
     halt();
     // Disconnect abnormally. The user code should reconnect using the mail client.
     errorStack.push(new Error(completions.poll(), message, wireTrace.list()));
     idler.disconnect();
   } finally {
     disconnected();
   }
 }
Esempio n. 27
0
  @Test
  public void testEmptyMembership() throws Exception {
    ZooKeeperClient zkClient1 = createZkClient(TIMEOUT);
    final CandidateImpl candidate1 = new CandidateImpl(createGroup(zkClient1));
    Reign candidate1Reign = new Reign("1", candidate1);

    candidate1.offerLeadership(candidate1Reign);
    assertSame(candidate1, candidateBuffer.takeLast());
    candidate1Reign.abdicate();
    assertFalse(candidate1.getLeaderData().isPresent());
  }
Esempio n. 28
0
  boolean awaitLogin() {
    try {
      if (!loginSuccess.await(10L, TimeUnit.SECONDS)) {
        disconnectAbnormally("Timed out waiting for login response");
        throw new RuntimeException("Timed out waiting for login response");
      }

      return isLoggedIn();
    } catch (InterruptedException e) {
      errorStack.push(new Error(null, e.getMessage(), wireTrace.list()));
      throw new RuntimeException("Interruption while awaiting server login", e);
    }
  }
Esempio n. 29
0
  public void processOperation(Operation op, RemoteFile file) {
    boolean isPossible = true;

    if (op.equals(Operation.READ)) {
      Slave avaliableSlave = null;
      for (Slave s : SlaveGroup.slaves) {
        if (!s.isBusy()) avaliableSlave = s;
      }
      for (Slave s : SlaveGroup.slaves) {
        if (s.isBusy()
            && s.getRemoteFile().getId() == file.getId()
            && !s.getCurrentOperation().equals(Operation.READ)) {
          // Coloca na fila
          waitingOperations.add(new WaitingOperation(file, op));
          isPossible = false;
        }
      }

      if (avaliableSlave != null && isPossible) avaliableSlave.processOperation(op, file);
    }

    if (op.equals(Operation.WRITE) || op.equals(Operation.CREATE) || op.equals(Operation.REMOVE)) {
      Slave avaliableSlave = null;
      for (Slave s : SlaveGroup.slaves) {
        if (!s.isBusy()) avaliableSlave = s;
      }
      for (Slave s : SlaveGroup.slaves) {
        if (s.isBusy() && s.getRemoteFile().getId() == file.getId()) {
          waitingOperations.add(new WaitingOperation(file, op));
          isPossible = false;
        }
      }

      if (avaliableSlave != null && isPossible) {
        avaliableSlave.processOperation(op, file);
      }
    }
  }
 /** request terminate worker thread and release all related resources */
 public void release() {
   mRequestQueue.clear();
   synchronized (mSync) {
     if (mIsRunning) {
       offerFirst(REQUEST_EGL_TASK_QUIT, 0, null);
       mIsRunning = false;
       try {
         mSync.wait();
       } catch (final InterruptedException e) {
         // ignore
       }
     }
   }
 }