dev@grizzly.java.net

Re: Orderly Shutdown of Server in ProtocalParser code

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 17 Jun 2009 22:14:30 -0400

Salut,

Parker Lord wrote:
> I have a server using the ProtocolParser to parse out message and then pass
> them into my message filter.
>
> How do I perform an orderly shutdown of the server when I receive a shutdown
> command from a client.
>
> I want to send a simple 'stop' string to the server, have it then initiate
> the shutdown of the server.
>
> Ideally would also like to be able to restart it.

OK let me try to see if I understand properly. Mainly, you want to be
able to support two protocol

(first)

client ---> protocol_a ---> server

(second)

client ---> protocol_b ---> server

where protocol_b is the 'stop' string. Security wise, I would not mix
the handling of protocol_a and protocol_b, but instead create 2
SelectorHandler, one for protocol_a, one for protocol_b. For the
SelectorHandler listening for protocol_b, I strongly recommend you bind
the Selectorhandler (the address) to 127.0.0.1 as if you open it to all
port, some malicious use can re-start your server.

For protocol_b, just write a simple ProtocolFilter that take read the
String from the byteBuffer, and if the byteBuffer contains the expected
String ('stop'), the do something like:


public boolean execute(Context ctx){

// Read from the ByteBuffer
// If stop, then

new Thread(){

   public void run(){
      ctx.getController().stop();
      ctx.getController.start();
}.start();

}

That should work. Did I understood your question correctly?

Thanks!

-- Jeanfrancois