[MINA] 0.9.0 - Need advice on implementing graceful shutdown
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Directory Project > [MINA] 0.9.0 - Need advice on implementing graceful shutdown




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    [MINA] 0.9.0 - Need advice on implementing graceful shutdown  
Srikanth Veeramachaneni


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-22-05 01:45 AM

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 =3D ioSessionsList.toArray(new IoSession[0]);
for (int i =3D 0; i < ioSessions.length; i++) {
IoSession session =3D ioSessions[i];
if (!session.isClosing()) {
session.suspendRead();
if (!(Boolean) session.getAttribute("HAS_PENDING_REQUESTS")) {
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.

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

thanks,
Srikanth






[ Post a follow-up to this message ]



    Re: [MINA] 0.9.0 - Need advice on implementing graceful shutdown  
Trustin Lee


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:37 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register