I don't understand the question. If the client has crashed how can it close the connection? It is no longer running.
Sorry for the unclear question.
I wish there's a way to close client connection from server side.
I found that I can register an Interceptor to handle events and wish to get a event while client crashed and close the client connection.
But I can't get such event to fail the RemotingConnection, or other way to close the client connection.
Can I do things like that?
1 of 1 people found this helpful
Also see user manual management chapter
Finally I extends NettyAcceptorFactory and decorate the ConnectionLifeCycleListener.
When connectionException is called, then lazy get a MBeanServerConnection to call closeConnectionsForAddress.
(But cast ConnectionLifeCycleListener to RemotingServiceImpl to getConnections)
Cast interface to implmentation is a bad thing, but we need to close it immediately..
Can I do it better?
It's not possible to always know on the server when the client has "crashed" immediately.
If the client machine just disappears or you pull out the network connection you will *not* get an exception on the server.
That''s just the way TCP works.
TCP is a reliable protocol in that it is designed to cope with temporary interruptions of network and lost packets, consequently pulling cable does not result in exceptions being thrown.
That's why we use a TTL. The only real way to be fairly sure a client has crashed is if you get no traffic from it for a certain time. Hence TTL.
In some cases you will get an exception e.g. if the client process is killed and the client machine and network is still alive - this is because when you kill the client process the OS will close it's TCP connections.
This is not true in the general case though.
Thank you very much!
Your explain is very clear, let me know where the design of TTL comes from and why I can't rely on the network exception.
Maybe I need to rethink the solution or design of my requirement.
How do you determine which IP address to send to HornetQServerControl.closeConnectionsForAddress? I thought perhaps I could associate certain meta data with the sessions and then determine on that, but I don't see a way to query that information on the server.
I decorate org.hornetq.spi.core.remoting.ConnectionLifeCycleListener to listen to connection exception.
Call closeConnectionsForAddress through mBean when connection exception happen.
Pass the ConnectionLifeCycleListener decorator into NettyAcceptor when NettyAcceptorFactoryImpl create it.
It's work around, but I can't find better way to close the connection immediately.
But my consumers are all in LAN with take care, so I think it's work for me.