My Solution?
I wrapped the instantiation of the class below, TimeServer, in another class
called ServerShell.
<who knows apache?? :) >ServerShell creates a "pid" file on the file
system then starts the TimeServer via its
runServer() method which creates the acceptor, executor, loads the filters
and ultimately calls the bind. Server
shell (who extends Thread) then "starts". This thread simply locks on an
Object, "waits" on it for 30 secs then tries
to open the pid file. If it can, so be it, ServerShell closes the file and
does an Object.notify(). If ServerShell
attempts to open the pid file and it throws a FileNotFound, the Ex is caught
and calls TimerServer.terminateServer()
(which in turn calls acceptor.unbind() and executor.shutdown()).
ServerShell then "notifies" the lock and ends.
Now, this is a pretty old, old school hack and I'll test the livin' wind out
of it 'cause I suspect it's (lack of) efficiency,
but might I suggest that a convenience class be implemented in MINA that
might allow this type of functionality?
It would seem to me that this type of structure (multi-threaded tail filter)
is likely going to be a common
"architecture" and a convenience class to light it up and put it out would
be, at the very least, helpful.
Thx all...Tm.
P.S. and despite this site's recommended "etiquette" to avoid small
talk..... DON'T! Small talk make you human.
threadMaven wrote:
>
> 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#a12509944
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.