Пример #1
0
  private void handleAcceptedSocket(ChannelEvent e) {
    if (e instanceof ChannelStateEvent) {
      ChannelStateEvent event = (ChannelStateEvent) e;
      SctpChannelImpl channel = (SctpChannelImpl) event.getChannel();
      ChannelFuture future = event.getFuture();
      ChannelState state = event.getState();
      Object value = event.getValue();

      switch (state) {
        case OPEN:
          if (Boolean.FALSE.equals(value)) {
            channel.worker.close(channel, future);
          }
          break;
        case BOUND:
        case CONNECTED:
          if (value == null) {
            channel.worker.close(channel, future);
          }
          break;
        case INTEREST_OPS:
          channel.worker.setInterestOps(channel, future, (Integer) value);
          break;
      }
    } else if (e instanceof MessageEvent) {
      MessageEvent event = (MessageEvent) e;
      SctpChannelImpl channel = (SctpChannelImpl) event.getChannel();
      boolean offered = channel.writeBuffer.offer(event);
      assert offered;
      channel.worker.writeFromUserCode(channel);
    }
  }
  @Override
  public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) throws Exception {
    if (e instanceof ChannelStateEvent) {
      ChannelStateEvent event = (ChannelStateEvent) e;
      NioClientSocketChannel channel = (NioClientSocketChannel) event.getChannel();
      ChannelFuture future = event.getFuture();
      ChannelState state = event.getState();
      Object value = event.getValue();

      switch (state) {
        case OPEN:
          if (Boolean.FALSE.equals(value)) {
            channel.getWorker().close(channel, future);
          }
          break;
        case BOUND:
          if (value != null) {
            bind(channel, future, (SocketAddress) value);
          } else {
            channel.getWorker().close(channel, future);
          }
          break;
        case CONNECTED:
          if (value != null) {
            connect(channel, future, (SocketAddress) value);
          } else {
            channel.getWorker().close(channel, future);
          }
          break;
        case INTEREST_OPS:
          channel.getWorker().setInterestOps(channel, future, ((Integer) value).intValue());
          break;
      }
    } else if (e instanceof MessageEvent) {
      MessageEvent event = (MessageEvent) e;
      NioSocketChannel channel = (NioSocketChannel) event.getChannel();
      boolean offered = channel.writeBufferQueue.offer(event);
      assert offered;
      channel.getWorker().writeFromUserCode(channel);
    }
  }
Пример #3
0
 @Override
 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
   // Send back the received message to the remote peer.
   transferredBytes.addAndGet(((ChannelBuffer) e.getMessage()).readableBytes());
   e.getChannel().write(e.getMessage());
 }