dev@grizzly.java.net

Re: Orderly Shutdown of Server in ProtocalParser code

From: Parker Lord <plord_at_seecontrol.com>
Date: Wed, 24 Jun 2009 09:51:06 -0700 (PDT)

I have tried this approach and it doesn't actually stop the application, it
doesnt appear to do anything.
This code is in my ProtocolFilter.
if(isStop)
      {
        new Thread()
        {
          public void run()
          {
            try
            {
              context.getController().stop();
            }
            catch(IOException ex)
            {}
          }
       }.start();
      }

I have another issue also, I dont seem to be able to get two Protocol Chains
to work at the same time.
I have the original one still defined which is registered using:

    controller.setProtocolChainInstanceHandler(pciHandler);

The question is however how to register the second one.

I tried:
    tcpAdminHandler.setProtocolChainInstanceHandler(pciAdminHandler);

to set it on the handler, but that did not work. I could see the app
listening on the correct IP address and port number, but it does not
actually call the ProtocolFilter.


here is my code to starts everything up.

  final ProtocolChain protocolChain = new DefaultProtocolChain();
    protocolChain.addFilter(parser);
    protocolChain.addFilter(filter);
    ((DefaultProtocolChain)protocolChain).setContinuousExecution(false);


    
    ProtocolChainInstanceHandler pciHandler = new
DefaultProtocolChainInstanceHandler()
    {
      public ProtocolChain poll()
      {
        return protocolChain;
      }

      public boolean offer(ProtocolChain protocolChain)
      {
        return false;
      }
    };
    

    // This is required to get the main Handler to be invoked.
    controller.setProtocolChainInstanceHandler(pciHandler);

    if (protocol.equals(ConnectorProtocol.TCP))
    {
      TCPSelectorHandler tcpHandler = new TCPSelectorHandler();
      tcpHandler.setPort(port);
      tcpHandler.setProtocolChainInstanceHandler(pciHandler);

      controller.addSelectorHandler(tcpHandler);
      controller.getSelectorHandler(Protocol.TCP).setAttribute("logging",
new Boolean(logging));
     
controller.getSelectorHandler(Protocol.TCP).setAttribute("xsdFilename",
xsdFilename);

    }
    else if (protocol.equals(ConnectorProtocol.UDP))
    {
      UDPSelectorHandler udpHandler = new UDPSelectorHandler();
      udpHandler.setPort(port);
      udpHandler.setProtocolChainInstanceHandler(pciHandler);

      controller.addSelectorHandler(udpHandler);
      controller.getSelectorHandler(Protocol.UDP).setAttribute("logging",
new Boolean(logging));
     
controller.getSelectorHandler(Protocol.UDP).setAttribute("xsdFilename",
xsdFilename);
    }

    // Add the admin handler
    final AdminMessageFilter adminMessageFilter = new AdminMessageFilter();

    final ProtocolChain protocolAdminChain = new DefaultProtocolChain();
    protocolAdminChain.addFilter(new ReadFilter());
    protocolAdminChain.addFilter(adminMessageFilter);
   
((DefaultProtocolChain)protocolAdminChain).setContinuousExecution(false);

    ProtocolChainInstanceHandler pciAdminHandler = new
DefaultProtocolChainInstanceHandler()
    {
      public ProtocolChain poll()
      {
        return protocolAdminChain;
      }

      public boolean offer(ProtocolChain protocolAdminChain)
      {
        return false;
      }
    };


    TCPSelectorHandler tcpAdminHandler = new TCPSelectorHandler();
    tcpAdminHandler.setInet(InetAddress.getByName("127.0.0.1"));
    tcpAdminHandler.setPort(ConnectorMain.defaultAdminPort);
    // This doesn't seem to work.
    tcpAdminHandler.setProtocolChainInstanceHandler(pciAdminHandler);
    controller.addSelectorHandler(tcpAdminHandler);


    ExecutorService threadPool = new PipelineThreadPool();
    controller.setThreadPool(threadPool);
    

    try
    {
      syslog.info("Starting listener for "+device+" devices.");
      controller.start();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }



Jeanfrancois Arcand-2 wrote:
>
> Salut,
>
> Parker Lord wrote:
>> Basically, the bigger issue is how to code the part that will cause the
>> process to exit.
>>
>> Looks like yours is a restart, so to stop I would just do:
>>
>> new Thread(){
>>
>> public void run(){
>> ctx.getController().stop();
>> }.start();
>>
>> That will cause the entire process and all threads to exit?
>
> Yes, that will stop the entire Grizzly application.
>
> A+
>
> -_ jeanfrancois
>
>

-- 
View this message in context: http://www.nabble.com/Orderly-Shutdown-of-Server-in-ProtocalParser-code-tp24081691p24188476.html
Sent from the Grizzly - Development mailing list archive at Nabble.com.