You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by mat <fo...@gmail.com> on 2007/04/24 20:34:36 UTC

Protocol codec filter

Hi folks,

I believe the protocol codec filter is to encode and decode message under
each session and I believe it uses IOService threads. My question is: what
if I try to boardcast the message to all sessions connected. The encode part
will be executed a lot of times. However, if I encode once and convert it to
bytebuffer. and send in LOOP session.write(byte[]). Which mean i don't need
protocol codec filter under this situation. Am I right?

Re: Protocol codec filter

Posted by Trustin Lee <tr...@gmail.com>.
For those who might read this thread later via the ML archive, I will
clarify a little bit more.

On 4/28/07, mat <fo...@gmail.com> wrote:
> After reading the ProtocolCodecFilter source code, now I understand. Thanks.

Yes, ProtocolCodecFilter doesn't pass a ByteBuffer to an encoder.
Calling IoSession.write() with a ByteBuffer will simply bypass the
encoding process.

> 2007/4/27, mat <fo...@gmail.com>:
> >
> > Can you explain in detail? How ProtocolCodecFilter will
> > not attempt to encode? I wrote the encoder by myself.
> >
> > The following message will never be called??
> >   public void encode(IoSession session, Object message,
> > ProtocolEncoderOutput out) throws Exception
> >     {
> >         AbstractMessage m = (AbstractMessage)message ;
> >         ByteBuffer buf = ByteBuffer.allocate(1024);
> >         buf.setAutoExpand(true); // Enable auto-expand for easier encoding
> >
> >         encodeBody(session, m, buf);
> >         buf.flip();
> >         out.write(buf);
> >     }
> >
> >
> >
> > 2007/4/26, peter royal <pr...@apache.org>:
> > >
> > > On Apr 25, 2007, at 9:52 AM, mat wrote:
> > > >>> You meant if I use session.write(bytebuffer) in IOHandler, the
> > > >>> encodeBody
> > > > in protocol filter will never be called?
> > > > So you can still use it for decoding safely.
> > > >>> You meant encoding?
> > >
> > >
> > > yes.. if you session.write(ByteBuffer), the ProtocolCodecFilter will
> > > not attempt to encode.
> > >
> > > -pete
> > >
> > >
> > > --
> > > proyal@apache.org - http://fotap.org/~osi
> > >
> > >
> > >
> > >
> > >
> >
>


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: Protocol codec filter

Posted by mat <fo...@gmail.com>.
After reading the ProtocolCodecFilter source code, now I understand. Thanks.

2007/4/27, mat <fo...@gmail.com>:
>
> Can you explain in detail? How ProtocolCodecFilter will
> not attempt to encode? I wrote the encoder by myself.
>
> The following message will never be called??
>   public void encode(IoSession session, Object message,
> ProtocolEncoderOutput out) throws Exception
>     {
>         AbstractMessage m = (AbstractMessage)message ;
>         ByteBuffer buf = ByteBuffer.allocate(1024);
>         buf.setAutoExpand(true); // Enable auto-expand for easier encoding
>
>         encodeBody(session, m, buf);
>         buf.flip();
>         out.write(buf);
>     }
>
>
>
> 2007/4/26, peter royal <pr...@apache.org>:
> >
> > On Apr 25, 2007, at 9:52 AM, mat wrote:
> > >>> You meant if I use session.write(bytebuffer) in IOHandler, the
> > >>> encodeBody
> > > in protocol filter will never be called?
> > > So you can still use it for decoding safely.
> > >>> You meant encoding?
> >
> >
> > yes.. if you session.write(ByteBuffer), the ProtocolCodecFilter will
> > not attempt to encode.
> >
> > -pete
> >
> >
> > --
> > proyal@apache.org - http://fotap.org/~osi
> >
> >
> >
> >
> >
>

Re: Protocol codec filter

Posted by mat <fo...@gmail.com>.
Can you explain in detail? How ProtocolCodecFilter will
not attempt to encode? I wrote the encoder by myself.

The following message will never be called??
  public void encode(IoSession session, Object message,
ProtocolEncoderOutput out) throws Exception
    {
        AbstractMessage m = (AbstractMessage)message ;
        ByteBuffer buf = ByteBuffer.allocate(1024);
        buf.setAutoExpand(true); // Enable auto-expand for easier encoding

        encodeBody(session, m, buf);
        buf.flip();
        out.write(buf);
    }



2007/4/26, peter royal <pr...@apache.org>:
>
> On Apr 25, 2007, at 9:52 AM, mat wrote:
> >>> You meant if I use session.write(bytebuffer) in IOHandler, the
> >>> encodeBody
> > in protocol filter will never be called?
> > So you can still use it for decoding safely.
> >>> You meant encoding?
>
>
> yes.. if you session.write(ByteBuffer), the ProtocolCodecFilter will
> not attempt to encode.
>
> -pete
>
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
>
>

Re: Protocol codec filter

Posted by peter royal <pr...@apache.org>.
On Apr 25, 2007, at 9:52 AM, mat wrote:
>>> You meant if I use session.write(bytebuffer) in IOHandler, the  
>>> encodeBody
> in protocol filter will never be called?
> So you can still use it for decoding safely.
>>> You meant encoding?


yes.. if you session.write(ByteBuffer), the ProtocolCodecFilter will  
not attempt to encode.

-pete


-- 
proyal@apache.org - http://fotap.org/~osi




Re: Protocol codec filter

Posted by mat <fo...@gmail.com>.
MINA's ProtocolCodecFilter is smart enough to not attempt an encode
if a ByteBuffer passes through it.
>>Now I use session.write(MyOwnMessage) in IOHandler. The encode happened in
protocol filter encodeBody.
>>You meant if I use session.write(bytebuffer) in IOHandler, the encodeBody
in protocol filter will never be called?
So you can still use it for decoding safely.
>>You meant encoding?

Re: Protocol codec filter

Posted by peter royal <pr...@apache.org>.
On Apr 24, 2007, at 11:34 AM, mat wrote:
> I believe the protocol codec filter is to encode and decode message  
> under
> each session and I believe it uses IOService threads. My question  
> is: what
> if I try to boardcast the message to all sessions connected. The  
> encode part
> will be executed a lot of times. However, if I encode once and  
> convert it to
> bytebuffer. and send in LOOP session.write(byte[]). Which mean i  
> don't need
> protocol codec filter under this situation. Am I right?

MINA's ProtocolCodecFilter is smart enough to not attempt an encode  
if a ByteBuffer passes through it.

So you can still use it for decoding safely.
-pete


-- 
proyal@apache.org - http://fotap.org/~osi