users@grizzly.java.net

Re: Setting timeouts on NIOTransportBuilder

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Tue, 27 Jan 2015 23:28:07 -0800

Hi,

we should've documented this more clear.
These 2 timeout values take effect only if you use Transport in blocking
mode.

In non-blocking mode (which is default) you can use Future.get(timeout,
timeunit) to limit the connect time and (as you mentioned)
IdleTimeoutFilter to close idle connections.

Thanks.

WBR,
Alexey.

On 27.01.15 06:00, Ben-Yosef Efrat wrote:
>
> 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.”