/** * Transfers attributes such as (de)serializers, singleUse etc to a new connection. When the * connection factory has a reference to a TCPListener (to read responses), or for single use * connections, the connection is executed. Single use connections need to read from the * connection in order to close it after the socket timeout. * * @param connection The new connection. * @param socket The new socket. */ protected void initializeConnection(TcpConnection connection, Socket socket) { TcpListener listener = this.getListener(); if (listener != null) { connection.registerListener(listener); } TcpSender sender = this.getSender(); if (sender != null) { connection.registerSender(sender); } connection.setMapper(this.getMapper()); connection.setDeserializer(this.getDeserializer()); connection.setSerializer(this.getSerializer()); connection.setSingleUse(this.isSingleUse()); }
protected TcpConnection wrapConnection(TcpConnection connection) throws Exception { if (this.interceptorFactoryChain == null) { return connection; } TcpConnectionInterceptorFactory[] interceptorFactories = this.interceptorFactoryChain.getInterceptorFactories(); if (interceptorFactories == null) { return connection; } for (TcpConnectionInterceptorFactory factory : interceptorFactories) { TcpConnectionInterceptor wrapper = factory.getInterceptor(); wrapper.setTheConnection(connection); // if no ultimate listener or sender, register each wrapper in turn if (this.listener == null) { connection.registerListener(wrapper); } if (this.sender == null) { connection.registerSender(wrapper); } connection = wrapper; } return connection; }