Le 2/21/14 6:10 PM, Max Larsson a écrit :
> Hi,
>
> i've got a very asynchronous protocol to implement. Where if have to
> respond as fast as possible to retrieve message.
>
> In my IoHandler i receive the desired message and write out the response
> to session.write. But it is not immediately written out. During my
> process of the message additional message are received and process
> before my response message is delivered.

It all depends on the session processing the incoming message. This is a
multi-threaded framework, messages comming from dfferent sessions may be
processed in //.
>
> Now i figured out that only one thread handles read/write request. 
Absolutely.

> And
> the read request is processed before any write request? 

depends. If the socket is full when the thread is trying to write into
it, then it give up, and a new incoming message might be processed
before the write can be done. Eventually, a lot of messages can be
stacked waiting for being written.

> So how can i
> either have a separate Thread for sending and receiving. 

You can use an Executor in the chain, even two executors if needed (one
for reads, one for writes). But at the nend of the day, it does not
somlve your issue.

> Or alternative
> how to tell the NioSocketprocess to take priority processing of write
> requests?

You can idle the read while the write is not processed. The way it works
woudl be something like :

- process a read (in the handler)
- idle the read (session.suspendRead())
- write the response

Then in the handler, react on the messageSent event :

- process the messageSent event
- un-idle the read (session.resumeRead())

You now can process a new read.

Think twice before implementing such a logic though !!! I would question
the fact that the client is sending messages but not reading the
response fast enough...

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to