Please tell me how to bind more than one port by Mina?
Please tell me how to bind more than one port by Mina,and how to set different Handlers by receiving massages from different ports. Please reply me as soon as possible. Thank you very much!
Re: Please tell me how to bind more than one port by Mina?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hi, To bind more than one port by Mina, I use the following: acceptor.bind(new InetSocketAddress(portNumber)); I don't know if I am using in the correct way, but works. Seems to me that you can not set different handlers for each port. What I do is to receive the message in a handler and call a different class according to the port Again, I don't know if I am doing in the correct way. Thanks. On 08/20/2012 05:28 AM, 轩辕嘉 wrote: Please tell me how to bind more than one port by Mina,and how to set different Handlers by receiving massages from different ports. Please reply me as soon as possible. Thank you very much! - -- {}S José Vilmar Estácio de Souza -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJQMgTpAAoJEPMEywZ3KXznfCcH/3cu00eDCNjP0JIEvC74XvaH DclqvZ+hE0FAN1y94ZmlhBrKcX7VOjQ0fmrmHAIe2zpv4SOjgKSl2ySvytLul/PD Yjq7b8GxQGHm2FMpLdx+5xBxK5cMznBTnZwhgeQz4EuWXoE1RkGXuvz/RcRwVOMD sNzGhkYN69oM6IlZqKrrg4wbsVDrCPlmRo9YbZ7uzah1o+Dt/U3w8BddzM3wLJEe plqzgMS+GAVI6CGK04jW0Or6+BU0e2Mz8jvRnC0X82R5t+QWwC8UuiPQqsN7GCk+ JuteBi7VVJ3yeE97iJUYQ8f15xsrXi0vhvvRwdNotmXH9ZCwsZ9egmzfM0XLtec= =tOpu -END PGP SIGNATURE-
Forcing the closure of any open session when mina server shuts down
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() ); 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
Re: Forcing the closure of any open session when mina server shuts down
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() ); 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
Re: Forcing the closure of any open session when mina server shuts down
Hello, thanks for the suggestion - i tried it out but it does not seem to work - the server listener port is closed (this worked for me before) however the client who connects still has the sessions opened. After doing a close(true) on all sessions - and confirming with acceptor.getManagedSessions().size() that there are indeed 0 sessions left - im puzzled who is to blame - the mina server or postfix ? Here is the netstat output after at least one session has been created (there are 2 mina services running, at 10027 and 10028) tcp0 0 127.0.0.1:10027 0.0.0.0:* LISTEN tcp0 0 127.0.0.1:10028 0.0.0.0:* LISTEN tcp0 0 127.0.0.1:54751 127.0.0.1:10028 ESTABLISHED tcp0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT tcp0 0 127.0.0.1:10028 127.0.0.1:54751 ESTABLISHED after i shutdown the server and a debug output confirmed that the address was unbind, and 0 sessions are left - im left with this tcp1 0 127.0.0.1:54751 127.0.0.1:10028 CLOSE_WAIT tcp0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT tcp0 0 127.0.0.1:10028 127.0.0.1:54751 FIN_WAIT2 the client is still connecting to 10027 and 28, and for some reason the server port for 10028 is still open but on fin_wait2. I also tried adding acceptor.dispose(); after unbind - no dice. Any further ideas? Thanks
Re: Forcing the closure of any open session when mina server shuts down
Hi, I am (for now) ignoring this line as it exists before exit and after: tcp0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT Apart from that the acceptor tcp ports have been closed (as there is no LISTEN in your second output. As for the remaining session (the 2 listings are the same session): If you use close(true) then the traditional close handshake (FIN -- FIN-ACK) does not take place in the correct way. Thus this would leave the port in the CLOSE_WAIT and other end FIN_WAIT2 state. To solve this you normally use close(false) and wait for the session to shutdown gracefully. You could built in a sleep of a few seconds to give the system the time to close the sessions. I haven't found a better way of doing this than doing a close(false) on all sessions, wait for example 30 seconds, and then a close(true). If anyone has a better way of handling this let me know as I cannot find a good way to handle these situations all over the internet. Maybe Emnanuel has a good solution for this. Hope my comments help you Regards, Mike Op 20-8-2012 13:56, Harakiri schreef: Hello, thanks for the suggestion - i tried it out but it does not seem to work - the server listener port is closed (this worked for me before) however the client who connects still has the sessions opened. After doing a close(true) on all sessions - and confirming with acceptor.getManagedSessions().size() that there are indeed 0 sessions left - im puzzled who is to blame - the mina server or postfix ? Here is the netstat output after at least one session has been created (there are 2 mina services running, at 10027 and 10028) tcp0 0 127.0.0.1:10027 0.0.0.0:* LISTEN tcp0 0 127.0.0.1:10028 0.0.0.0:* LISTEN tcp0 0 127.0.0.1:54751 127.0.0.1:10028 ESTABLISHED tcp0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT tcp0 0 127.0.0.1:10028 127.0.0.1:54751 ESTABLISHED after i shutdown the server and a debug output confirmed that the address was unbind, and 0 sessions are left - im left with this tcp1 0 127.0.0.1:54751 127.0.0.1:10028 CLOSE_WAIT tcp0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT tcp0 0 127.0.0.1:10028 127.0.0.1:54751 FIN_WAIT2 the client is still connecting to 10027 and 28, and for some reason the server port for 10028 is still open but on fin_wait2. I also tried adding acceptor.dispose(); after unbind - no dice. Any further ideas? Thanks
Re: Forcing the closure of any open session when mina server shuts down
Hello, thanks for your input - i tried it with both close(true) and close(false) - but i would expect that close(false) blocks till all sessions are really closed - however the doc states something about flushing pending writes - i dont think there are any pending writes when the connection is just idle. The 30sec sleep is a workaround, but for me i would have to use 60sec maybe... or alternatively - when starting the server try for 60sec to open the used port again. Anyway, there should be a better solution =/ --- On Mon, 8/20/12, Mike van Goor m...@probie.nl wrote: From: Mike van Goor m...@probie.nl Subject: Re: Forcing the closure of any open session when mina server shuts down To: users@mina.apache.org Date: Monday, August 20, 2012, 8:17 AM Hi, I am (for now) ignoring this line as it exists before exit and after: tcp 0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT Apart from that the acceptor tcp ports have been closed (as there is no LISTEN in your second output. As for the remaining session (the 2 listings are the same session): If you use close(true) then the traditional close handshake (FIN -- FIN-ACK) does not take place in the correct way. Thus this would leave the port in the CLOSE_WAIT and other end FIN_WAIT2 state. To solve this you normally use close(false) and wait for the session to shutdown gracefully. You could built in a sleep of a few seconds to give the system the time to close the sessions. I haven't found a better way of doing this than doing a close(false) on all sessions, wait for example 30 seconds, and then a close(true). If anyone has a better way of handling this let me know as I cannot find a good way to handle these situations all over the internet. Maybe Emnanuel has a good solution for this. Hope my comments help you Regards, Mike Op 20-8-2012 13:56, Harakiri schreef: Hello, thanks for the suggestion - i tried it out but it does not seem to work - the server listener port is closed (this worked for me before) however the client who connects still has the sessions opened. After doing a close(true) on all sessions - and confirming with acceptor.getManagedSessions().size() that there are indeed 0 sessions left - im puzzled who is to blame - the mina server or postfix ? Here is the netstat output after at least one session has been created (there are 2 mina services running, at 10027 and 10028) tcp 0 0 127.0.0.1:10027 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:10028 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:54751 127.0.0.1:10028 ESTABLISHED tcp 0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT tcp 0 0 127.0.0.1:10028 127.0.0.1:54751 ESTABLISHED after i shutdown the server and a debug output confirmed that the address was unbind, and 0 sessions are left - im left with this tcp 1 0 127.0.0.1:54751 127.0.0.1:10028 CLOSE_WAIT tcp 0 0 127.0.0.1:56901 127.0.0.1:10027 TIME_WAIT tcp 0 0 127.0.0.1:10028 127.0.0.1:54751 FIN_WAIT2 the client is still connecting to 10027 and 28, and for some reason the server port for 10028 is still open but on fin_wait2. I also tried adding acceptor.dispose(); after unbind - no dice. Any further ideas? Thanks
Re: Forcing the closure of any open session when mina server shuts down
Le 8/20/12 2:41 PM, Harakiri a écrit : Hello, thanks for your input - i tried it with both close(true) and close(false) - but i would expect that close(false) blocks till all sessions are really closed - however the doc states something about flushing pending writes - i dont think there are any pending writes when the connection is just idle. You can also call the servise.dispose( boolean ) method. If the parameter is 'true', the service will try to flush all the pending writes. Otherwise, it will immediately close all the sessions. -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: Forcing the closure of any open session when mina server shuts down
--- On Mon, 8/20/12, Emmanuel Lécharny elecha...@gmail.com wrote: From: Emmanuel Lécharny elecha...@gmail.com Subject: Re: Forcing the closure of any open session when mina server shuts down To: users@mina.apache.org Date: Monday, August 20, 2012, 8:54 AM Le 8/20/12 2:41 PM, Harakiri a écrit : Hello, thanks for your input - i tried it with both close(true) and close(false) - but i would expect that close(false) blocks till all sessions are really closed - however the doc states something about flushing pending writes - i dont think there are any pending writes when the connection is just idle. You can also call the servise.dispose( boolean ) method. If the parameter is 'true', the service will try to flush all the pending writes. Otherwise, it will immediately close all the sessions. I think most of my issues result in the rebinding of the port - in java there is setReuseAddress(boolean on) // Enable/disable the SO_REUSEADDR socket option for a serversockt - is there something similar for mina? I found in the archive your post about acceptor.getSessionConfig().setReuseAddress but that does not exist in 2.x
Re: Forcing the closure of any open session when mina server shuts down
Le 8/20/12 3:28 PM, Harakiri a écrit : --- On Mon, 8/20/12, Emmanuel Lécharny elecha...@gmail.com wrote: From: Emmanuel Lécharny elecha...@gmail.com Subject: Re: Forcing the closure of any open session when mina server shuts down To: users@mina.apache.org Date: Monday, August 20, 2012, 8:54 AM Le 8/20/12 2:41 PM, Harakiri a écrit : Hello, thanks for your input - i tried it with both close(true) and close(false) - but i would expect that close(false) blocks till all sessions are really closed - however the doc states something about flushing pending writes - i dont think there are any pending writes when the connection is just idle. You can also call the servise.dispose( boolean ) method. If the parameter is 'true', the service will try to flush all the pending writes. Otherwise, it will immediately close all the sessions. I think most of my issues result in the rebinding of the port - in java there is setReuseAddress(boolean on) // Enable/disable the SO_REUSEADDR socket option for a serversockt - is there something similar for mina? I found in the archive your post about acceptor.getSessionConfig().setReuseAddress but that does not exist in 2.x Of course it does ! public class DefaultSocketSessionConfig extends AbstractSocketSessionConfig { ... public void setReuseAddress(boolean reuseAddress) { this.reuseAddress = reuseAddress; } The thing is that you have to cast the acceptor.getSessionConfig() to be able to set the flag, because it implements an interface which is a bit generic (IoSessionConfig) : ((SocketSessionConfig)acceptor.getSessionConfig() ).setReuseAddress( true ); Or you can set it for the whole service : SocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.setReuseAddress( true ); -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: Forcing the closure of any open session when mina server shuts down
--- On Mon, 8/20/12, Emmanuel Lécharny elecha...@gmail.com wrote: From: Emmanuel Lécharny elecha...@gmail.com Subject: Re: Forcing the closure of any open session when mina server shuts down To: users@mina.apache.org Cc: elecha...@apache.org Date: Monday, August 20, 2012, 9:37 AM Le 8/20/12 3:28 PM, Harakiri a écrit : Or you can set it for the whole service : SocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.setReuseAddress( true ); Yes thank you - i figured as much - i just changed it from IoAcceptor acceptor; to NioSocketAcceptor acceptor;