/** * Initialize the {@code SocketChannel}. * * This method initializes a new channel created by the {@code ServerBootstrap} * * The default implementation create a remote connection, configures a default pipeline * which handles coding/decoding messages, handshaking, timeout and error handling based * on {@code RpcConfig} instance provided at construction time. * * On each call to this method, every handler added must be a new instance. As of now, the * handlers cannot be shared across connections. * * Subclasses can override it to add extra handlers if needed. * * @param ch the socket channel */ protected void initChannel(final SocketChannel ch) throws SSLException { C connection = initRemoteConnection(ch); connection.setChannelCloseHandler(newCloseListener(ch, connection)); final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(PROTOCOL_ENCODER, new RpcEncoder("s-" + rpcConfig.getName())); pipeline.addLast(MESSAGE_DECODER, newDecoder(connection.getAllocator())); pipeline.addLast(HANDSHAKE_HANDLER, newHandshakeHandler(connection)); if (rpcConfig.hasTimeout()) { pipeline.addLast(TIMEOUT_HANDLER, new LoggingReadTimeoutHandler(connection, rpcConfig.getTimeout())); } pipeline.addLast(MESSAGE_HANDLER, new InboundHandler(connection)); pipeline.addLast(EXCEPTION_HANDLER, new RpcExceptionHandler<>(connection)); }