private void connectionReceived(SocketChannel channel) { final ISocketChannel socketChannel = socketChannelFactory.createServerChannel(channel); final PendingHandshakeConnection conn = new PendingHandshakeConnection(socketChannel, null, INCOMING); if (socketChannel.requiresHandshake()) { asyncHandshake(conn); } else { conn.handshakeSuccess = true; handshakeCompletedConnections.add(conn); } }
private void accept() { SocketChannel channel = null; SelectionKey channelKey = null; try { channel = serverSocketChannel.accept(); register(channel); final ISocketChannel serverChannel = socketChannelFactory.createServerChannel(channel); channelKey = channel.register(selector, SelectionKey.OP_READ); if (serverChannel.requiresHandshake()) { asyncHandshake(serverChannel, null, channelKey); } else { connectionReceived(serverChannel, channelKey); } } catch (IOException e) { LOGGER.error("Failed to accept channel ", e); close(channelKey, channel); } }
private void connectionAccepted(SocketChannel socketChannel) { try { NetworkUtil.configure(socketChannel); socketChannel.configureBlocking(false); final INetworkSecurityManager networkSecurityManager = appCtx.getServiceContext().getControllerService().getNetworkSecurityManager(); final ISocketChannelFactory socketChannelFactory = networkSecurityManager.getSocketChannelFactory(); final ISocketChannel serverChannel = socketChannelFactory.createServerChannel(socketChannel); //start a new thread to handle the request appCtx.getThreadExecutor().execute(new ReplicationWorker(serverChannel)); } catch (Exception e) { LOGGER.error("failed to process accepted connection", e); } }