[英]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. 我正在考虑将Java NIO实现转移到JBoss Netty,因为它提供的模型比我实现的更为简洁 。 The implementation manages a number of client connections to components over TCP using a proprietary protocol.
该实现使用专有协议通过TCP管理与组件的许多客户端连接。
One aspect of my implementation, that I cannot see in Netty, is the ability to set arbitrary timeouts, which: 我在Netty中看不到的实现的一个方面是设置任意超时的能力,该超时是:
ReadTimeoutHandler
but can the timeout value be changed/turned off easily by the Component as it moves through the state machine? ReadTimeoutHandler
但是当组件在状态机中移动时,可以轻易地更改/关闭该超时值吗? Can this timeout mechanism be accomplished using Netty? 可以使用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. 结论 :鉴于我需要实现一个超时机制,该机制将在其自己的线程中运行,所以我最终不会转换为使用Netty。
See ChannelConfig . 参见ChannelConfig 。 The method setConnectTimeoutMillis(int) sets the timeout in milliseconds.
setConnectTimeoutMillis(int)方法设置超时(以毫秒为单位)。 You can invoke this method via a Bootstrap instance by calling setOption(String, Object) .
您可以通过Bootstrap实例调用setOption(String,Object)来调用此方法。 The
name
would be "connectTimeoutMillis" and the value
would be the desired timeout in milliseconds. name
将为“ connectTimeoutMillis”,其value
将是所需的超时(以毫秒为单位)。
The following snippet shows how to set the connect timeout to 5000 milliseconds (5 seconds). 以下代码段显示了如何将连接超时设置为5000毫秒(5秒)。
ClientBootstrap bootstrap... // bootstrap instance
bootstrap.setOption("connectTimeoutMillis", 5000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.