Thank you for reply. I didn't fully understand what you said last night. Today I read your message again and found it's really a great approach to this problem. I even needn't create a new ThreadPoolExecutor.
According what you said, one messasgeWritten trigers another messageWrite until the prioritized queue in the filter is fully consumed. It just solved my problem. Many thanks! -------------------------------------------------- From: "Emmanuel Lecharny" <elecha...@gmail.com> Sent: Tuesday, December 15, 2009 8:38 PM To: <dev@mina.apache.org> Subject: Re: How do I send prioritized messages with Mina? > 刘伟 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 > > >