You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Michael Bauroth <mi...@falcom.de> on 2006/04/12 08:13:27 UTC

How do ProtocolDecoders work in a chain?

Hi,

sorry for the cross-posting (original question is located in 
'Implementation details'). On the other side I think it's meaningful to 
extract this question out there because it could be helpful for other 
developers too.

My question: What happens with the output (ProtocolDecoderOutput - 
POJOs) of different protocol decoders in a chain? Will it be sent 
directly to the IoSession or can I receive and modify it in other 
decoders, which are inserted later in the chain?

Sample: ByteBuffer -> TextLineDecoder (works on ByteBuffer) -> (single 
lines / Strings as POJOs)  -> ????  -> OwnDecoder (works on ByteBuffer / 
POJO ???)

Hope you can make the stuff clear for me.

Regards
Michael

Re: How do ProtocolDecoders work in a chain?

Posted by Michael Bauroth <mi...@falcom.de>.
Thanx for the quick response ...

Trustin Lee wrote:
> Hi Michael,
> 
> My question: What happens with the output (ProtocolDecoderOutput -
> 
>>POJOs) of different protocol decoders in a chain? Will it be sent
>>directly to the IoSession or can I receive and modify it in other
>>decoders, which are inserted later in the chain?
> 
> 
> 
> ProtocolEncoder and ProtocolDecoder are wrapped by ProtocolCodecFilter,
> which is an IoFilter.  So It becomes a part of the whole chain for an
> IoSession. No filters are allowed to send events to IoHandler directly.
> It's an implicit principal.
> 
> If you inserted one ProtocolCodecFilter, then it will be passed to
> IoHandler.messageReceived because there's no more filters in the chain.
> Otherwise, the object, as a result of decoding, will be passed to the next
> filter in the chain.
> 
> You can layer two ProtocolCodecFilters because already decoded messages are
> not processed by the second ProtocolCodecFilter.  Only ByteBuffers will be
> decoded.  You can use this trick to implement your protocol as a
> multi-layered stack.

This means on the other side:

... codecs behind TextLineCodec shouldn't work when all the input was 
line based, because all the stuff is decoded yet in TextLineCodec to 
single lines?

... if I want to use line separation among with other decoding 
algorithms, i must overload TextLineCodec itself or implement codec with 
equivalent functionality instead of using it as "preprocessor" in my chain?

Regards
Michael

> 
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
> 


-- 


_____ Falcom Wireless Communications GmbH ______________________________

Dipl.-Ing. Michael Bauroth
Manager Software Department

Phone:   +49 3677 8042 332
Fax:     +49 3677 8042 215
E-mail:  michael.bauroth@falcom.de

Address: Gewerbering 6, 98704 Langewiesen, Germany

______________________________ www.falcom.de ___________________________

This e-mail and any files transmitted are the property of FALCOM and/or
its affiliates, are confidential, and are intended solely for the use of
the individual or entity to whom this e-mail is addressed. If you are
not one of the named recipients or otherwise have reason to believe that
you have received this e-mail in error, please notify the sender and
delete this message immediately from your computer. Any other use,
retention, dissemination, forwarding, printing or copying of this e-mail
is strictly prohibited.

Re: How do ProtocolDecoders work in a chain?

Posted by Trustin Lee <tr...@gmail.com>.
Hi Michael,

On 4/12/06, Michael Bauroth <mi...@falcom.de> wrote:
>
> Hi,
>
> sorry for the cross-posting (original question is located in
> 'Implementation details'). On the other side I think it's meaningful to
> extract this question out there because it could be helpful for other
> developers too.


No problem. :)

My question: What happens with the output (ProtocolDecoderOutput -
> POJOs) of different protocol decoders in a chain? Will it be sent
> directly to the IoSession or can I receive and modify it in other
> decoders, which are inserted later in the chain?


ProtocolEncoder and ProtocolDecoder are wrapped by ProtocolCodecFilter,
which is an IoFilter.  So It becomes a part of the whole chain for an
IoSession. No filters are allowed to send events to IoHandler directly.
It's an implicit principal.

If you inserted one ProtocolCodecFilter, then it will be passed to
IoHandler.messageReceived because there's no more filters in the chain.
Otherwise, the object, as a result of decoding, will be passed to the next
filter in the chain.

You can layer two ProtocolCodecFilters because already decoded messages are
not processed by the second ProtocolCodecFilter.  Only ByteBuffers will be
decoded.  You can use this trick to implement your protocol as a
multi-layered stack.

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: How do ProtocolDecoders work in a chain?

Posted by Niklas Therning <ni...@trillian.se>.
Niklas Therning wrote:
> Michael Bauroth wrote:
> 
>> ...
>>
>> My question: What happens with the output (ProtocolDecoderOutput - 
>> POJOs) of different protocol decoders in a chain? Will it be sent 
>> directly to the IoSession or can I receive and modify it in other 
>> decoders, which are inserted later in the chain?
>>
>> Sample: ByteBuffer -> TextLineDecoder (works on ByteBuffer) -> (single 
>> lines / Strings as POJOs)  -> ????  -> OwnDecoder (works on ByteBuffer 
>> / POJO ???)
> 
> 
> Message objects created by a decoder will passed on to the next filter 
> in the chain. If the ProtocolCodecFilter is the last filter in the chain 
> the decoded message will be passed on to your IoHandler implementation.
> 
> You could definitely chain ProtocolCodecFilters which use different 
> decoders. However, you must make sure they are compatible. The first 
> decoders output must be compatible with the second decoders input etc. 
> For example, both TextLineDecoder and the decoders created by 
> DemuxingProtocolCodecFactory expects the input to be ByteBuffers. This 
> means you cannot chain them.

Ok, after reading Trusin's reply I must correct myself. You can chain 
ProtocolCodecFilters but the second decoder will only be used if the 
first decoder emitts a ByteBuffer. Otherwise, the second decoder will be 
ignored.

/Niklas

Re: How do ProtocolDecoders work in a chain?

Posted by Niklas Therning <ni...@trillian.se>.
Michael Bauroth wrote:
> ...
> 
> My question: What happens with the output (ProtocolDecoderOutput - 
> POJOs) of different protocol decoders in a chain? Will it be sent 
> directly to the IoSession or can I receive and modify it in other 
> decoders, which are inserted later in the chain?
> 
> Sample: ByteBuffer -> TextLineDecoder (works on ByteBuffer) -> (single 
> lines / Strings as POJOs)  -> ????  -> OwnDecoder (works on ByteBuffer / 
> POJO ???)

Message objects created by a decoder will passed on to the next filter 
in the chain. If the ProtocolCodecFilter is the last filter in the chain 
the decoded message will be passed on to your IoHandler implementation.

You could definitely chain ProtocolCodecFilters which use different 
decoders. However, you must make sure they are compatible. The first 
decoders output must be compatible with the second decoders input etc. 
For example, both TextLineDecoder and the decoders created by 
DemuxingProtocolCodecFactory expects the input to be ByteBuffers. This 
means you cannot chain them.

/Niklas