On Mon 31.08.2009 15:23, Emmanuel Lecharny wrote:
Aleksandar Lazic wrote:
If so, as soon as the messageReceived() method can have access to this
connection, then you are all set.

Hm I thought to use the session object but I can use a singelton
object from the 'xml-class', maybe this is the better way ;-)

Storing the reference into the session is ok. Otherwise, you don't
have to use a singleton, it's enough to initialize your handler
correctly, by passing a reference to the application. Remember that
the application will create the network layer (containing the server
and the handler), and it can initialize this part as you want. Your
code can be like that :

init application
init backend connection (with pooling if needed) -> Connection instance is created
init server ( Connection Instance )

you store the connection instance as a field in your handler :

class MyHandler extends IoHandlerAdapter {
 private MyConnectionToBackend cnx;

 public MyHandler( MyConnectionToBackend cnx ) {
   this.cnx = cnx;
 }

 messageReceived( blah ) {
   ...
   cnx.send( blah );
 }
}

You are done.

Thanks, sounds good.

I go back and take your input, if anybody interested in my solution I
can post it when it's done.

Maybe I will come back with some more questions ;-)

BR

Aleks

Reply via email to