12-22-05 12:45 PM
Hi Srikanth,
2005/12/22, Srikanth Veeramachaneni <sveerama-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:[vbco
l=seagreen]
>
> I would like to implement graceful shutdown of a MINA server.
>
> The features I would like to support for the graceful shutdown are
>
> 1. Stop listening for new connections
> 2. Suspend read on all open IO sessions
> 3. Wait until all pending requests are processed for open IO sessions
> 4. Send a message to the clients indicating the session is being closed
> due to server shutdown
> 5. Close all IO sessions
>
> Assuming that sessions are added and removed from a list using the
> sessionOpened()
> and sessionClosed() methods of the IO handler and information as to
> whether a
> session has pending requests is maintained as a session attribute,
> would an approach like below work?
>
> -------------------------------------------------------
> private ServiceRegistry registry;
> private List<IoSession> ioSessionsList;
>
> /**
> * pseudo code for supporting MINA server graceful shutdown
> */
> public void shutdown() {
> registry.unbindAll();
> while (!ioSessionsList.isEmpty()) {
> IoSession[] ioSessions = ioSessionsList.toArray(new IoSession
1;0]);
> for (int i = 0; i < ioSessions.length; i++) {
> IoSession session = ioSessions[i];
> if (!session.isClosing()) {
> session.suspendRead();
> if (!(Boolean) session.getAttribute("HAS_PENDING_REQUESTS"))
23;
> session.write("Server closing connection due to shutdown");
> session.close();
> }
> }
> }
> }
> }
> -------------------------------------------------------
>
> I would appreciate any advice/feedback/suggestions from MINA experts
> or anyone who has already implemented something similar.[/vbcol]
Your approach looks reasonable, but please test enough.
I probably need to add some synchronization to the above approach if
> it is a reasonable approach.
Actually we're going to add an option which enables automatic client
disconnection on unbind. It is not yet implemented, but we'll ship this
feature before 1.0 is released.
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
PGP Key ID: 0x854B996C
[ Post a follow-up to this message ]
|