Hello,
In short: You are responsible for every session that has been created
after MINA accepted it.
If you do not close them upon shutdown, they will remain in a
to-be-closed state for 2 minutes (I thought this was FIN-Wait, not sure).
To make sure the sessions are closed you should close them and then
unbind the port.
You can accomplish this by using a shutdownhook added to runtime.
Like before declaring the acceptor you do:
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
for(IoSession sess : _nioAcceptor.getManagedSessions().values())
{
sess.close(false); // Make this true if you want to force the
closure
}
nioAcceptor.unbind();
}
});
Op 20-8-2012 11:49, Harakiri schreef:
Hello,
i read the FAQ entry about closing sessions here mina.apache.org/faq.html and
also through the mailling list.
However im not sure how i should apply it to my use case.
I've created a very simple policy service similar to this example
http://jglatre.blogspot.de/2009/03/implementing-greylist-for-postfix-with.html
The faq states something about
ConnectFuture cf = connector.connect(new InetSocketAddress("localhost", 8080));
but i dont see how this applies to an IoAcceptor - i start my service like in
the above example
IoAcceptor acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new
ApdCodecFactory()));
acceptor.setHandler( new DummyApdHandler() );
acceptor.getSessionConfig().setReadBufferSize( 2048 );
acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
acceptor.bind( new InetSocketAddress(6666) );
i would expect that upon VM shutdown that all open sessions are closed -
however they are not - my postfix server keeps a session open for quiet a while
- so when i restart my java server (standalone service) i get the bind error -
address already in use.
Any hints? I tried a shutdown hook and manually do a acceptor.unbind() but that
didnt do the trick either!
Thanks