users@grizzly.java.net

Setting timeouts on NIOTransportBuilder

From: Ben-Yosef Efrat <Efrat.Ben-Yosef_at_comverse.com>
Date: Tue, 27 Jan 2015 14:00:18 +0000

Hello Everyone,

I want to set a connection timeout (timeout for trying to open a connection) and an execution timeout.
Im using a NIOTransportBuilder variable and use the setClientSocketSoTimeout() and the setConnectionTimeout().
Upon opening connection I do something like:

Connection exitPointConnection = null;

Future<Connection> future = endPointTransport.connect(aExitPointHost,aExitPointPort);

                                  try
                                  {
                                         // Obtain the connection
                                         exitPointConnection = future.get(ClientSocketSoTimeout+ConnectionTimeout,TimeUnit.SECONDS);
                                  }
                                  catch (TimeoutException | InterruptedException | ExecutionException ex)
                                  {
                                         sLogger.error(MessageFormat.format("Failed to connect network interface for [{0}] and port [{1}]", new Object[]{aExitPointHost, aExitPointPort}),ex);
                                  }

                                  // Need to handle a case where no connection is established!
                                  if (exitPointConnection != null && exitPointConnection.isOpen() == true)
                                  {
                                         isExitPointConnected = true;

                                         // Attach the shared session data object to the newly created connection
                                         SessionStateManager.attach(exitPointConnection,exitPointSessionData);

                                         // Align the session data(as the shared session data parameter can be null)
                                         exitPointSessionData = SessionStateManager.acquire(exitPointConnection);

                                         //update the session id on this thread for logs
                                         SessionIDForLoging.updateSessionIdToLogs(exitPointSessionData);

                                         // Put the newly created connection on the shared session data
                                         exitPointSessionData.put(StateDataAttributesKeys.EXIT_POINT_CONNECTION,exitPointConnection);

                                         sLogger.info(MessageFormat.format("Exit point for [{0}] is Open",new Object[] {exitPointConnection.getPeerAddress().toString()}));
                                  }

I see two unexplained behaviors:

1. No matter what I set for the connection timeout, if the ip Im trying to connect to is down, the get() method wait as long as its first parameter. So where does the connection timeout takes place?

2. After a connection was established successfully, Im executing a command and causes the end point to wait with an answer. I get stuck until the timeout of the timeout filter. So I don't understand the use of ClientSocketSoTimeout. Is there any way to set an execution timeout (other then the timeout filter)?


Thanks a lot
Efrat
________________________________
"This e-mail message may contain confidential, commercial or privileged information that constitutes proprietary information of Comverse Inc. or its subsidiaries. If you are not the intended recipient of this message, you are hereby notified that any review, use or distribution of this information is absolutely prohibited and we request that you delete all copies and contact us by e-mailing to: security_at_comverse.com. Thank You."