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?
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.
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.