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
On 5/2/06, Trustin Lee <[EMAIL PROTECTED]> wrote:
Hi Michael,
There's a org.apache.mina.handler.multiton package which will help you in
this case.
But, basically, you shouldn't have many calls to IoSession.get/setAttribute()
if you store only one object which has all states.
HTH,
Trustin
On 5/3/06, Michael Bauroth <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I think about a customized IoSession, where I can store specific data
> instead in a Map in direct member variables or a session dependend
> config object. The reason is, that I have a lot of session specific data
> (protocol related start and stop markers, state variables and so on),
> which I must request in each decode step as quick as possible. Two
> questions:
>
> 1. Do you think, that it is Mina conform?
>
> 2. How could I do that? Which classes must be overriden, that all works
> together?
>
> Regards
> Michael
>
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6