예제 #1
0
 @Override
 public void run() {
   try {
     messagesReplayed = journalReader.readFully(this);
   } catch (Exception ex) {
     LangUtil.rethrowUnchecked(ex);
   }
 }
예제 #2
0
  public SelectionKey registerForRead(final ReceiveChannelEndpoint transport) {
    SelectionKey key = null;
    try {
      transports = ArrayUtil.add(transports, transport);
      key = transport.receiveDatagramChannel().register(selector, SelectionKey.OP_READ, transport);
    } catch (final ClosedChannelException ex) {
      LangUtil.rethrowUnchecked(ex);
    }

    return key;
  }
예제 #3
0
  public int pollTransports() {
    int bytesReceived = 0;
    try {
      if (transports.length <= ITERATION_THRESHOLD) {
        for (final ReceiveChannelEndpoint transport : transports) {
          bytesReceived += poll(transport);
        }
      } else {
        selector.selectNow();

        final SelectionKey[] keys = selectedKeySet.keys();
        for (int i = 0, length = selectedKeySet.size(); i < length; i++) {
          bytesReceived += poll((ReceiveChannelEndpoint) keys[i].attachment());
        }

        selectedKeySet.reset();
      }
    } catch (final IOException ex) {
      LangUtil.rethrowUnchecked(ex);
    }

    return bytesReceived;
  }