简体   繁体   中英

Flexible timeout mechanism in JBoss Netty?

I am considering moving my Java NIO implementation over to JBoss Netty as it provides a much cleaner model than I have implemented. The implementation manages a number of client connections to components over TCP using a proprietary protocol.

One aspect of my implementation, that I cannot see in Netty, is the ability to set arbitrary timeouts, which:

  1. Wait for some data to be read from the Component. I know that Netty has a ReadTimeoutHandler but can the timeout value be changed/turned off easily by the Component as it moves through the state machine?
  2. Wait for time to elapse so that I can reconnect to the Component (to give the Component time to be restarted after a disconnect). This is entirely unrelated to communication and is a simple timeout, however I'd like the timeout 'event/exception' to be presented to the handler class in the same manner as other communication-related timeouts.

Can this timeout mechanism be accomplished using Netty?

Conclusion : Given I would need to implement a timeout mechanism, which would run within the its own thread, I am not going to convert to using Netty after all.

See ChannelConfig . The method setConnectTimeoutMillis(int) sets the timeout in milliseconds. You can invoke this method via a Bootstrap instance by calling setOption(String, Object) . The name would be "connectTimeoutMillis" and the value would be the desired timeout in milliseconds.

The following snippet shows how to set the connect timeout to 5000 milliseconds (5 seconds).

ClientBootstrap bootstrap... // bootstrap instance
bootstrap.setOption("connectTimeoutMillis", 5000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM