directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Srikanth Veeramachaneni <>
Subject [MINA] 0.9.0 - Need advice on implementing graceful shutdown
Date Thu, 22 Dec 2005 02:00:46 GMT
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
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() {
    while (!ioSessionsList.isEmpty()) {
      IoSession[] ioSessions = ioSessionsList.toArray(new IoSession[0]);
      for (int i = 0; i < ioSessions.length; i++) {
        IoSession session = ioSessions[i];
        if (!session.isClosing()) {
          if (!(Boolean) session.getAttribute("HAS_PENDING_REQUESTS")) {
            session.write("Server closing connection due to shutdown");

I would appreciate any advice/feedback/suggestions from MINA experts
or anyone who has already implemented something similar.

I probably need to add some synchronization to the above approach if
it is a reasonable approach.


View raw message