刘伟 a écrit :
I'm working on a streaming server using Mina, there are
two types of packets in my server: the control messages that's short but with
higher priority, and the media packets that's big but with lower priority. I
know inside mina there's a message queue maintained for written messages, so
that the write request can return immediately. This makes thing pretty bad: if I
want to write a control message, the queue is filled with media data and the
control message is sent until all media data is flushed.
So I'm expecting a method like:
IoSession.write(IoBuffer message, int priority). For the remaining messages in
the queue, the ones with lower priority always get sent before the ones with
higher priority. Does anyone know there be some package can help me do this? Or
do I need to override an existing Mina class - maybe NioProcessor?
One way to handle this is to write a filter you'll add at the beginning
of the chain (ie, it will be the last one executed before the messages
will be queued to be written). This filter will itself manage the queue
of messages, and can manage the priority.
Messages will be written one by one, and only when the previous one has
been sent (ie, the selector is ready for Write). IFAIR, you know that
when the messageSent event is received. Then you can send the next
message. If there is a higher priority message arriving, then you can
immediately write it.
I *think* this approach can work, assuming that the messageSent can
really be handled in this filter. Writing such a filter should not be a
complex task, and I guess a POC can we whipped in a few hourd.
Hope it helps.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com