示例#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();
    }
  }