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);
    }
  }
  private void handleServerSocket(ChannelEvent e) {
    if (!(e instanceof ChannelStateEvent)) {
      return;
    }

    ChannelStateEvent event = (ChannelStateEvent) e;
    SctpServerChannelImpl channel = (SctpServerChannelImpl) event.getChannel();
    ChannelFuture future = event.getFuture();
    ChannelState state = event.getState();
    Object value = event.getValue();

    switch (state) {
      case OPEN:
        if (Boolean.FALSE.equals(value)) {
          close(channel, future);
        }
        break;
      case BOUND:
        if (value != null) {
          bind(channel, future, (SocketAddress) value);
        } else {
          close(channel, future);
        }
      case INTEREST_OPS:
        if (event instanceof SctpBindAddressEvent) {
          SctpBindAddressEvent bindAddressEvent = (SctpBindAddressEvent) event;
          bindAddress(channel, bindAddressEvent.getFuture(), bindAddressEvent.getValue());
        }

        if (event instanceof SctpUnbindAddressEvent) {
          SctpUnbindAddressEvent unbindAddressEvent = (SctpUnbindAddressEvent) event;
          unbindAddress(channel, unbindAddressEvent.getFuture(), unbindAddressEvent.getValue());
        }
        break;
    }
  }
 @Override
 public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
   channel = e.getChannel();
 }