}
public void elementSunk(
ChannelPipeline pipeline, ChannelEvent element) throws Exception {
if (element instanceof ChannelStateEvent) {
ChannelStateEvent event = (ChannelStateEvent) element;
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)) {
NioWorker.close(channel, future);
}
break;
case BOUND:
if (value != null) {
bind(channel, future, (SocketAddress) value);
} else {
NioWorker.close(channel, future);
}
break;
case CONNECTED:
if (value != null) {
connect(channel, future, (SocketAddress) value);
} else {
NioWorker.close(channel, future);
}
break;
case INTEREST_OPS:
NioWorker.setInterestOps(channel, future, ((Integer) value).intValue());
break;
}
} else if (element instanceof MessageEvent) {
MessageEvent event = (MessageEvent) element;
NioSocketChannel channel = (NioSocketChannel) event.getChannel();
channel.writeBuffer.offer(event);
NioWorker.write(channel);
}
}