directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maarten Bosteels <m.boste...@pandora.be>
Subject [mina] how to close session for reading
Date Sat, 19 Nov 2005 20:15:43 GMT
Hi,

Is there a direct way to close a session for reading (I am using mina 
0.8.x).
Obviously I can't close the session in messageReceived, since the 
response has to get sent.
But when I wait until messageSent, I run the risk that messages are 
being processed after I closed the session. (see the logs)
Am I guaranteed that the next messageReceived will only be fired after 
the previous messageSent has finsihed ?
Then I could check protocolSession.isConnected before processing a 
message, right ?
Or should I rely on a custom attribute in my session (actually I already 
have to) .

Ok, I see the faq states "all events generated by MINA are transmitted 
to your handlers in order"

Wouldn't it be more elegant if you could do session.closeForInput()  in 
messageReceive() ?
and the decoder wouldn't waste cycles on messages that you don't want to 
pocess anyway.

Thanks,
Maarten

  public void messageReceived(ProtocolSession protocolSession, Object o) 
throws Exception {
    logger.info("received [" + o +"] - connected: " + 
protocolSession.isConnected());
    protocolSession.write(o);
    if ("close".equals(o)) {
      protocolSession.setAttribute("closed", Boolean.TRUE);
    }
  }

  public void messageSent(ProtocolSession protocolSession, Object o) 
throws Exception {
    logger.info("sent [" + o +"] - connected: " + 
protocolSession.isConnected());
    if (protocolSession.getAttribute("closed")!= null) {
      logger.info("closing session");
      protocolSession.close();
      logger.info("session closed");
    }
  }

2005-11-19 20:35:05,861   MyClient - written request [12345]
2005-11-19 20:35:05,931   MyServer - received [12345] - connected: true
2005-11-19 20:35:05,961   MyClient - read response [12345]
2005-11-19 20:35:05,971   MyClient - written request [close]
2005-11-19 20:35:05,971   MyServer - sent [12345] - connected: true
2005-11-19 20:35:05,981   MyServer - received [close] - connected: true
2005-11-19 20:35:05,991   MyClient - read response [close]
2005-11-19 20:35:05,991   MyClient - written request [54321]
2005-11-19 20:35:06,001   MyServer - sent [close] - connected: true
2005-11-19 20:35:06,011   MyServer - closing session
2005-11-19 20:35:06,011   MyClient - end-of-file
2005-11-19 20:35:06,021   MyServer - session closed
2005-11-19 20:35:06,021   MyServer - received [54321] - connected: false



Mime
View raw message