Muhammad Ichsan a écrit :
On Wed, Feb 3, 2010 at 9:46 PM, Emmanuel LŽcharny <[email protected]> wrote:
Muhammad Ichsan a écrit :
But, I wonder the purpose of session in sessionOpened.
You may add some logic when the session is opened.
But some logics are forbidden? Like send messages using the session.
yes. Let's me explain why you can't send a message in the sessionOpened() method.

When an event is generated (like the sessionOpened), it goes through a chain of filters, then hit the application (the handler). When the application has finished to process this event, it returns, and the chain is unfolded, up to the place the event has been pushed to the chain. When it's done, then the Thread is available for the next event to be processed. The IoProcessor can kick and select one Thred to process the event. In your case, when you write a message in yur application, it's just pushed in a queue to be processed when there will be an available thread. So you can't process them until you are done ith the event processing, which explains why all the messages are sent in one shot.

Adding an executor in the chain can help here, are it introduce some point for other Threads to be available to process the newly added events.

Anyway, it's a bit complicated, and frankly, it's better not to send any message here, unless you want the server to start pushing data to the client (then add an executor in the chain)
Also, what
about if the server sends the messages first? How can I get the
session?

You can't. The server won't create a session on a client, or it will be
called 'client', not server !

Please see this: http://pastebin.com/d18d1ea9b
yes, so ?

Reply via email to