示例#1
0
 public void run() {
   try {
     List<InterHubMessage> messages = new ArrayList<InterHubMessage>();
     try {
       while (true) {
         lock.lock();
         try {
           queue.take(messages);
         } finally {
           lock.unlock();
         }
         for (InterHubMessage message : messages) {
           connection.dispatch(message);
           if (message instanceof EndOfStream) {
             connection.flush();
             return;
           }
         }
         connection.flush();
         messages.clear();
       }
     } finally {
       lock.lock();
       try {
         connectionState.dispatchFinished();
       } finally {
         lock.unlock();
       }
     }
   } catch (Throwable t) {
     errorHandler.execute(t);
   }
 }
示例#2
0
 public void run() {
   try {
     List<InterHubMessage> messages = new ArrayList<InterHubMessage>();
     try {
       while (true) {
         lock.lock();
         try {
           queue.take(messages);
         } finally {
           lock.unlock();
         }
         for (InterHubMessage message : messages) {
           if (message instanceof EndOfStream) {
             boundedDispatch.endStream();
             return;
           }
           if (message instanceof ChannelMessage) {
             ChannelMessage channelMessage = (ChannelMessage) message;
             dispatch.dispatch(channelMessage.getPayload());
           } else if (message instanceof RejectedMessage) {
             RejectedMessage rejectedMessage = (RejectedMessage) message;
             listener.messageDiscarded(rejectedMessage.getPayload());
           } else {
             throw new IllegalArgumentException(
                 String.format("Don't know how to handle message %s", message));
           }
         }
         messages.clear();
       }
     } finally {
       lock.lock();
       try {
         queue.stop();
       } finally {
         lock.unlock();
       }
     }
   } catch (Throwable t) {
     errorHandler.execute(t);
   }
 }