Hi :
I find it wrong because of two IoBuffer hashcode is equal if they have the
same bytes .
Why not add the message to the EncodedWriteRequest as member ?


2008/10/18 吴峥涛 <[EMAIL PROTECTED]>

> hi :
> I have a  client socket application using mina ,  and I want get the
> message sent order in one session.
>
> The ProtocolCodecFilter.filterWrite will  flush  once more .  The first
> flushing offer a  EncodedWriteRequest into the session's writeRequestQueue
> ,   the second flushing offer  the  MessageWriteRequest  into the session's
> writeRequestQueu.
>
> I want put the message into a queue , after  the encoded message is sent in
> the NioProcessor's worker thread .   But  the first EncodedWriteRequest
> hasn't writefuture ,  so I can't using IoFutureListener<WriteFuture> ; and
> even if  I implement the IoFilterAdaptor's messageSent ,   can get the
> encodedMessage not the message.
>
>
> So I have to  keep a map from encodedMessage to message .
>
> public class CommandEncoder extends ProtocolEncoderAdapter {
>   public void encode(IoSession session, Object message,
>             ProtocolEncoderOutput out) throws Exception {
>         CommandQueueItem item = (CommandQueueItem) message;
>         IoBuffer buf =
> item.getCommand().toBuf(MemcachedConstants.DEFAULT_CHARSET);
>         buf.setAutoExpand(true);
>         buf.flip();
>
>         ConcurrentHashMap<IoBuffer , CommandQueueItem>  map=
> (ConcurrentHashMap<IoBuffer,CommandQueueItem>)session.getAttribute("encodedMessage2Message");
>         map.put(buf, item);
>
>         out.write(buf);
>     }
> }
>
>
>
> public class AppendFilter extends IoFilterAdapter {
>
>     @SuppressWarnings("unchecked")
>     @Override
>     public void messageSent(NextFilter nextFilter, IoSession session,
>             WriteRequest writeRequest) throws Exception {
>         Object obj = writeRequest.getMessage();
>         if(    obj instanceof IoBuffer )
>         {
>             IoBuffer buf = (IoBuffer) obj;
>
>             ConcurrentHashMap<IoBuffer  ,   CommandQueueItem >
> encodedMessage2Message =
>                 (ConcurrentHashMap<IoBuffer, CommandQueueItem>)
> session.getAttribute("encodedMessage2Message");
>
>             CommandQueueItem item =   encodedMessage2Message.get(buf);
>
>             // ignore
>
>         }
>         nextFilter.messageSent(session , writeRequest);
>     }
>
>
>
> }
>
>
> It's so ugly ,  can anyone give me a better way ? 3x
>
>
>

Reply via email to