Any response would be greatly appreciated.
------------------------------------------
M.V.S.Kishore
91-9886412814


On Wed, 31 Jan 2024 at 22:17, Kishore Mokkarala <[email protected]>
wrote:

> Hi Emmanuel,
>
> Do we need to create a new instance of SSLFilter per tcp ip connection or
> can we reuse it ?
>
> For example, do we need to repeat the same code for each tcp ip connection
> ?
>
> *Approach 1:*
> for(int i=0;i< 500;i++)
> {
> NioSocketConnector connector = new NioSocketConnector();
> connector.getFilterChain().addLast("LoggingFilter",
> G10CaptureService.loggingFilter);
> connector.getFilterChain().addLast("codecFilter",
> G10CaptureService.probeCodecFilter);
> connector.getFilterChain().addLast("executorFilter",
> G10CaptureService.executorFilter);
> connector.getFilterChain().addLast("gpbMessageFilter",
> G10CaptureService.gpbMessageFilter);
> connector.getFilterChain().addLast("keepAliveFilter",
> G10CaptureService.keepAliveFilter);
> SslFilter sslFilter;
> try {
> SSLContext sslContext = TLSUtil.getSSLContext();
> sslFilter = new CustomSslFilter(sslContext);
> connector.getFilterChain().addFirst("sslFilter", sslFilter);
> } catch (Exception e) {
> e.printStackTrace();
> LOG.error("Exception during creating SSL context..." +
> XError.getStackTrace(e));
> }
> //io handler creation
> StateMachine stateMachine =
> StateMachineFactory.getInstance(IoHandlerTransition.class).create(
>                 G10MinaClient.CONNECTED, new G10MinaClient(processor));
>
>         IoHandler ioHandler = new
> StateMachineProxyBuilder().setStateContextLookup(
>                 new IoSessionStateContextLookup(new StateContextFactory() {
>                     @Override
>                     public StateContext create() {
>                         final G10StateContext stateContext = new
> G10StateContext();
>                         stateContext.setStartedTime(new Date());
>                         LOG.info("G10StateContext initialized at:{}
> ",System.currentTimeMillis());
>                         return stateContext;
>                     }
>                 })).create(IoHandler.class, stateMachine);
> connector.setHandler(ioHandler);
> connector.connect(primaryAddress);
> connectFuture.awaitUninterruptibly();
> if (connectFuture.isConnected()) {
> IoSession session = connectFuture.getSession();
> // Do something with the session if needed
> } else {
> System.err.println("Connection failed for iteration: " + i);
> }
> }
>
> *Approach 2:*
> Reuse the generic connector implemented above for opening all TCP/IP
> connections.
> //just do the below for getting connections for example
> NioSocketConnector connector = new NioSocketConnector();
> //filter chain creation
> //add SSLFilter to filer chain
>
> for(int i=0;i< 500;i++)
> {
> ConnectFuture connectFuture = connector.connect(serverAddress);
> connectFuture.awaitUninterruptibly();
> if (connectFuture.isConnected()) {
> IoSession session = connectFuture.getSession();
> // Do something with the session if needed
> } else {
> System.err.println("Connection failed for iteration: " + i);
> }
> }
>
> Which approach is better ?
>
> Regards,
> ------------------------------------------
> M.V.S.Kishore
> 91-9886412814
>

Reply via email to