Thanx for the suggestions. I will give it a trial :)
But once more: Doesn't it make sense for Mina to implement a standard
config to IoSession by default like the SessionConfig for Acceptors i.e. ?
Regards
Michael
Srikanth Veeramachaneni wrote:
Hi Michael,
I had a similar need and I addressed it exactly as Trustin suggested.
Here is an example which illustrates the approach. Using this approach
whenever I need access to the custom session instance I do
MySession mySession = MySession.getSession(IoSession);
--------------------------------------------------------------------------
/**
* Simple custom session object to maintain my own state information.
*/
public class MySession {
private static final String FQCN = MySession.class.getName();
private static final String KEY = FQCN + ".KEY";
public static MySession getSession(IoSession aSession) {
return (MySession) aSession.getAttribute(KEY);
}
private IoSession session;
// DEFINE all custom instance variables needed to maintain state.
public MySession(IoSession aSession) {
this.session = aSession;
aSession.setAttribute(KEY, this);
}
}
--------------------------------------------------------------------------
/**
* IO Handler to illustrate use of custom session. Creates a MySession
* instance and stores it as an attribute in IoSession.
*/
public class MyHandler extends IoHandlerAdapter {
public void sessionCreated(IoSession aSession) throws Exception {
super.sessionCreated(aSession);
MySession mySession = new MySession(aSession);
}
}
--------------------------------------------------------------------------
thanks,
Srikanth