You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Adam Brown <ac...@gmail.com> on 2009/06/02 19:08:19 UTC

How do I shutdown a MINA 2.0 server?

I'm trying to modify our server to allow a message to cause it to clean up
and exit.  Currently, I've got code in our IoHandler that receives the
message and cleans up 'everything else', but when I try to unbind() the
IoAcceptor, the thread exits and leaves the connection unclosed (ie: the
telnet session I am testing with remains open).  Additionally, I still see a
couple of MINA-related threads running (and NioProcessor thread & some
thread-pool threads).

What am I missing?  Am i going about this the wrong way?

-adam

Re: How do I shutdown a MINA 2.0 server?

Posted by Emmanuel Lecharny <el...@apache.org>.
On Wed, Jun 3, 2009 at 7:52 AM, David Rosenstrauch <da...@darose.net> wrote:
> On Tue, June 2, 2009 6:46 pm, Emmanuel Lecharny wrote:
>> On Tue, Jun 2, 2009 at 10:18 PM, Adam Brown <ac...@gmail.com> wrote:
>>> Thanks, David.  Having a listener on the CloseFuture solved the problem
>>> for
>>> me.  Now everything shuts down cleanly.
>>
>> I'm pretty sure it would be better to define a way to programatically
>> shutdown the server without having to implement a 'hack' (btw, David,
>> brillant idea !)
>
> Not such a hack really, if you think about it.  It kinda makes sense that
> you'd want to finish gracefully closing the connection issuing the
> shutdown command before you shut down the server.

The fact is there is no other way to do it in MINA atm. I call a
'hack' the fact that you _have_ to do that, and I wish MINA offer a
better solution...





-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: How do I shutdown a MINA 2.0 server?

Posted by David Rosenstrauch <da...@darose.net>.
On Tue, June 2, 2009 6:46 pm, Emmanuel Lecharny wrote:
> On Tue, Jun 2, 2009 at 10:18 PM, Adam Brown <ac...@gmail.com> wrote:
>> Thanks, David.  Having a listener on the CloseFuture solved the problem
>> for
>> me.  Now everything shuts down cleanly.
>
> I'm pretty sure it would be better to define a way to programatically
> shutdown the server without having to implement a 'hack' (btw, David,
> brillant idea !)

Not such a hack really, if you think about it.  It kinda makes sense that
you'd want to finish gracefully closing the connection issuing the
shutdown command before you shut down the server.

DR


Re: How do I shutdown a MINA 2.0 server?

Posted by Emmanuel Lecharny <el...@apache.org>.
On Tue, Jun 2, 2009 at 10:18 PM, Adam Brown <ac...@gmail.com> wrote:
> Thanks, David.  Having a listener on the CloseFuture solved the problem for
> me.  Now everything shuts down cleanly.

I'm pretty sure it would be better to define a way to programatically
shutdown the server without having to implement a 'hack' (btw, David,
brillant idea !)

But I think that giving access to the sevrer acceptors is probably a
good idea, assuming you can control who is sending the shutdown
message...

This is something we can discuss on the dev list

(also I think that documenting the server shutdown on the site would
be a good idea)
-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: How do I shutdown a MINA 2.0 server?

Posted by Adam Brown <ac...@gmail.com>.
Thanks, David.  Having a listener on the CloseFuture solved the problem for
me.  Now everything shuts down cleanly.

-adam

On Tue, Jun 2, 2009 at 10:47 AM, David Rosenstrauch <da...@darose.net>wrote:

> Adam Brown wrote:
>
>> I'm trying to modify our server to allow a message to cause it to clean up
>> and exit.  Currently, I've got code in our IoHandler that receives the
>> message and cleans up 'everything else', but when I try to unbind() the
>> IoAcceptor, the thread exits and leaves the connection unclosed (ie: the
>> telnet session I am testing with remains open).  Additionally, I still see
>> a
>> couple of MINA-related threads running (and NioProcessor thread & some
>> thread-pool threads).
>>
>> What am I missing?  Am i going about this the wrong way?
>>
>> -adam
>>
>
> I basically do shutdown same as you.  Only difference is that I close the
> open session first:
>
> public class ShutdownCommand extends TextProtocolCommand {
> ...
>        public ProtocolResponse execute() throws Exception {
> ...
>                CloseFuture closeFuture =
> getSession().close(closeImmediately);
>                closeFuture.addListener(new CloseSessionListener());
>                return null;
>        }
> ...
>        class CloseSessionListener implements IoFutureListener<CloseFuture>
> {
>                public void operationComplete(CloseFuture future) {
>                        getServerControl().shutDown();
>                }
>        }
> }
>
>
> public class CacheServer implements CacheServerControl {
> ...
>        public void shutdown() {
>                logger.debug("{} protocol processor shutting down server
> socket", protocolType);
>                protocolAcceptor.unbind();
>                protocolAcceptor.dispose();
>        }
>
>        private String protocolType;
>        private SocketAcceptor protocolAcceptor;
>        private Logger logger;
> }
>
>
>
> Maybe try doing a thread dump and see where in the code the remaining
> threads are hanging.
>
> HTH,
>
> DR
>

Re: How do I shutdown a MINA 2.0 server?

Posted by boB Gage <bg...@ekosystems.com>.
If  'closeImmediately' in this line:
> CloseFuture closeFuture = getSession().close(closeImmediately); 
resolves to false, I have observed Mina to leave behind a couple threads 
in WAIT states that in my experience never came out of that state.   In 
my case, changing the getSession().close(false) to 
getSession().close(true) stopped that problem dead in its tracks.

boB


David Rosenstrauch wrote:
> Adam Brown wrote:
>> I'm trying to modify our server to allow a message to cause it to 
>> clean up
>> and exit.  Currently, I've got code in our IoHandler that receives the
>> message and cleans up 'everything else', but when I try to unbind() the
>> IoAcceptor, the thread exits and leaves the connection unclosed (ie: the
>> telnet session I am testing with remains open).  Additionally, I 
>> still see a
>> couple of MINA-related threads running (and NioProcessor thread & some
>> thread-pool threads).
>>
>> What am I missing?  Am i going about this the wrong way?
>>
>> -adam
>
> I basically do shutdown same as you.  Only difference is that I close 
> the open session first:
>
> public class ShutdownCommand extends TextProtocolCommand {
> ...
>     public ProtocolResponse execute() throws Exception {
> ...
>         CloseFuture closeFuture = getSession().close(closeImmediately);
>         closeFuture.addListener(new CloseSessionListener());
>         return null;
>     }
> ...
>     class CloseSessionListener implements IoFutureListener<CloseFuture> {
>         public void operationComplete(CloseFuture future) {
>             getServerControl().shutDown();
>         }
>     }
> }
>
>
> public class CacheServer implements CacheServerControl {
> ...
>     public void shutdown() {
>         logger.debug("{} protocol processor shutting down server 
> socket", protocolType);
>         protocolAcceptor.unbind();
>         protocolAcceptor.dispose();
>     }   
>
>     private String protocolType;
>     private SocketAcceptor protocolAcceptor;
>     private Logger logger;
> }
>
>
>
> Maybe try doing a thread dump and see where in the code the remaining 
> threads are hanging.
>
> HTH,
>
> DR

-- 
boB Gage
Software Engineer
Merge Healthcare


This message is a PRIVATE communication. This message and all
attachments are a private communication and may be confidential or
protected by privilege. If you are not the intended recipient, you are
hereby notified that any disclosure, copying, distribution or use of the
information contained in or attached to this message is strictly
prohibited. Please notify the sender of the delivery error by replying
to this message, and then delete it from your system. Thank you.


Re: How do I shutdown a MINA 2.0 server?

Posted by David Rosenstrauch <da...@darose.net>.
Adam Brown wrote:
> I'm trying to modify our server to allow a message to cause it to clean up
> and exit.  Currently, I've got code in our IoHandler that receives the
> message and cleans up 'everything else', but when I try to unbind() the
> IoAcceptor, the thread exits and leaves the connection unclosed (ie: the
> telnet session I am testing with remains open).  Additionally, I still see a
> couple of MINA-related threads running (and NioProcessor thread & some
> thread-pool threads).
> 
> What am I missing?  Am i going about this the wrong way?
> 
> -adam

I basically do shutdown same as you.  Only difference is that I close 
the open session first:

public class ShutdownCommand extends TextProtocolCommand {
...
	public ProtocolResponse execute() throws Exception {
...
		CloseFuture closeFuture = getSession().close(closeImmediately);
		closeFuture.addListener(new CloseSessionListener());
		return null;
	}
...
	class CloseSessionListener implements IoFutureListener<CloseFuture> {
		public void operationComplete(CloseFuture future) {
			getServerControl().shutDown();
		}
	}
}


public class CacheServer implements CacheServerControl {
...
	public void shutdown() {
		logger.debug("{} protocol processor shutting down server socket", 
protocolType);
		protocolAcceptor.unbind();
		protocolAcceptor.dispose();
	}	

	private String protocolType;
	private SocketAcceptor protocolAcceptor;
	private Logger logger;
}



Maybe try doing a thread dump and see where in the code the remaining 
threads are hanging.

HTH,

DR

Re: How do I shutdown a MINA 2.0 server?

Posted by Emmanuel Lecharny <el...@apache.org>.
Adam Brown wrote:
> I'm trying to modify our server to allow a message to cause it to clean up
> and exit.  Currently, I've got code in our IoHandler that receives the
> message and cleans up 'everything else', but when I try to unbind() the
> IoAcceptor, the thread exits and leaves the connection unclosed (ie: the
> telnet session I am testing with remains open).  Additionally, I still see a
> couple of MINA-related threads running (and NioProcessor thread & some
> thread-pool threads).
>
> What am I missing?  Am i going about this the wrong way?
>   

Normally, doing a acceptor.unbind(), sessions should be closed.

I'm investigating the issue atm.

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org