private void actualClose(final Context closeContext, final Handler<Void> done) { if (id != null) { vertx.sharedNetServers().remove(id); } for (DefaultNetSocket sock : socketMap.values()) { sock.internalClose(); } // We need to reset it since sock.internalClose() above can call into the close handlers of // sockets on the same thread // which can cause context id for the thread to change! Context.setContext(closeContext); ChannelGroupFuture fut = serverChannelGroup.close(); if (done != null) { fut.addListener( new ChannelGroupFutureListener() { public void operationComplete(ChannelGroupFuture channelGroupFuture) throws Exception { executeCloseDone(closeContext, done); } }); } }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { Channel ch = e.getChannel(); DefaultNetSocket sock = socketMap.get(ch); if (sock != null) { ChannelBuffer buff = (ChannelBuffer) e.getMessage(); sock.handleDataReceived(new Buffer(buff.slice())); } }
@Override public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) { final NioSocketChannel ch = (NioSocketChannel) e.getChannel(); final DefaultNetSocket sock = socketMap.remove(ch); if (sock != null) { sock.getContext() .execute( new Runnable() { public void run() { sock.handleClosed(); } }); } }
@Override public void channelInterestChanged(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { final NioSocketChannel ch = (NioSocketChannel) e.getChannel(); final DefaultNetSocket sock = socketMap.get(ch); ChannelState state = e.getState(); if (state == ChannelState.INTEREST_OPS) { sock.getContext() .execute( new Runnable() { public void run() { sock.handleInterestedOpsChanged(); } }); } }