Hey all, 
I thought I would re-post this question again, seeing that I have now gone
deeper into it and can explain myself a little better.^--^
so here we go.....
The code below is an extension of the TimeServer example in the
documentation. I've simply  mashed it with the 
"Configuring Thread Model tutorial" also provided in the documentation. Now,
it simply has a number of threads behind it serving up the original date
string.  The snippet below is the gist of it....
        
        //// create thread pool
        executor =
Executors.newCachedThreadPool(Executors.defaultThreadFactory());
        
        //// create my acceptor and associate the executor with it
        acceptor = new
SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1, executor);
        
        //// as per recommended mode of operation....
        IoServiceConfig acceptorConfig = acceptor.getDefaultConfig();
        acceptorConfig.setThreadModel(ThreadModel.MANUAL); 
        //// let's configure our filter chain
        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.getSessionConfig().setReuseAddress( true );
        //// a logging filter
        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
        //// a simple text codec
        cfg.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new
TextLineCodecFactory( Charset.forName( "UTF-8" ))));
       
///////////////////////////////////////////////////////////////////////////////////////////
        //// lastly I add in my thread pool.
       
///////////////////////////////////////////////////////////////////////////////////////////
        cfg.getFilterChain().addLast("threadPool", new
ExecutorFilter(executor));
        
        try {
            //// create the socket object
            iSA = new InetSocketAddress(InetAddress.getByName("localhost"), 
9110);
           
////////////////////////////////////////////////////////////////////////////////////////
            //// create my handler which casts each msg in 
            ////             messageReceived(IoSession session, Object msg)
            //// to a String then looks for "quit", if so it
            //// closes the "session".... exactly as the example does. 
           
////////////////////////////////////////////////////////////////////////////////////////
            TimeIOHandler tioh = new TimeIOHandler();
            ////  turn over the server.
            System.out.println("Server is binding, waiting for connections");
            acceptor.bind(iSA, tioh, cfg);
        } catch (UnknownHostException e) {
            .
            .etc
            .etc
            .etc
            
            
            
Now let's suppose that my TimeIOHandler class can detect the presence of a
command whose intent is to
effectively shutdown my server process, i.e. culminating with
anacceptor.unbind() and executor.shutdown().

So after much ado, my question: how can that detecting session thread get a
handle back to the acceptor and 
executor object to call the unbind() and shutdown() methods respectively.

A credible approach, IMHO:), would be creating a filter, executed before the
"threadPool" task, and using that to detect the "quitServer" command but
even then I don't know how to "get back to" the acceptor and/or executor
objects????

help?!

Tm
            
-- 
View this message in context: 
http://www.nabble.com/Serverside-shutdown-tf4386708s16868.html#a12506470
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.

Reply via email to