Apache MINA 会话关闭回调

发布于 2024-11-26 10:43:58 字数 500 浏览 0 评论 0原文

Apache Mina - 2.0.1

我有一个 IoHandlerAdapter,它具有 sessionOpened 和 sessionClosed 回调。当我打开会话时,我登录到服务器并开始发送请求,在“sessionClosed”中我只需重新启动我的应用程序。

我的应用程序进行了检查

if(!session.isClosing()) {
   //write to socket
} else {
   //throw a runtime exception. Hopefully the sessionClosed API gets 
   //called soon and the next time this call will succeed.
}

但是我确实注意到虽然 session.isClosing() 返回 true 但会话实际上永远不会关闭。即,我没有真正在我的处理程序中收到回电。这可能吗?我怎样才能减轻这种风险。有人可以解释调用关闭回调需要多长时间吗?

Apache Mina - 2.0.1

I have a IoHandlerAdapter which has call backs on sessionOpened and sessionClosed. When I open a session I login to the server and start sending requests, in "sessionClosed" I just restart my application.

My application makes a check

if(!session.isClosing()) {
   //write to socket
} else {
   //throw a runtime exception. Hopefully the sessionClosed API gets 
   //called soon and the next time this call will succeed.
}

However I did notice that although the session.isClosing() returns true the session actually never gets closed. i.e, I dont really get the call back in my handler. Is this possible? How can I mitigate against such a risk. Can someone explain how long it takes for the close callback to be called?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

负佳期 2024-12-03 10:43:58

恕我直言,您应该对这种情况使用 CloseFuture,如下所示:

CloseFuture future = session.close(true);
// wait until its closed, up to 1 minute
future.awaitUninterruptibly(60000L);
if (future.isClosed()) {
    System.out.println("Previous connection close completed");
}

IMHO you should use a CloseFuture for this senario like so:

CloseFuture future = session.close(true);
// wait until its closed, up to 1 minute
future.awaitUninterruptibly(60000L);
if (future.isClosed()) {
    System.out.println("Previous connection close completed");
}
¢蛋碎的人ぎ生 2024-12-03 10:43:58

我也见过这个。我相信这可能是 MINA 层中的竞争条件:

http://mail-archives.apache.org/mod_mbox/mina-dev/200802.mbox/%[电子邮件受保护]%3E

I have seen this too. I believe this could be a race condition in the MINA layer:

http://mail-archives.apache.org/mod_mbox/mina-dev/200802.mbox/%[email protected]%3E

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文