Beispiel #1
0
  /**
   * Process one message and either place it into the <code>responseMap</code> for a waiting thread
   * or send it to the dispatcher.
   */
  private void processOneMessage() {
    IProbeMessage message;

    try {
      message = serializer.readMessage();
    } catch (ChannelException e) {
      interrupt();
      return;
    } catch (Exception e) {
      logger.error("Error reading message", e);
      return;
    }

    if (message.isResponse()) {

      synchronized (responseMap) {
        if (isAbandoned(message.getSequenceNumber())) {
          return;
        }

        responseMap.put(message.getSequenceNumber(), message);
        responseMap.notifyAll();
        return;
      }
    }

    if (dispatcher != null) {
      try {
        dispatcher.dispatch(messenger, message);
      } catch (MessengerException e) {
        e.printStackTrace();
      }
    }
  }
Beispiel #2
0
  /** Main message reader loop. */
  public void run() {
    logger.debug("Starting message reader");

    while (!interrupted()) {
      processOneMessage();
    }

    responseMap.clear();
    messenger.close();
  }