Frederic Soulier wrote:
> Hi
> 
> Is there a way to bypass a decoder in the chain?
> For example, I have Decoder1 and Decoder2 registered in my
> DemuxingProtocolCodecFactory. My understanding is if I write to the
> ProtocolDecoderOutput then it will be forwarded to the next decoder in
> the chain, in that case Decoder2.

This is not how it works I'm afraid. :) What you write to the
ProtocolDecoderOutput will not be forwarded to the next decoder
registered with the same DemuxingProtocolCodecFactory. The decoded
message will be forwarded to the filter after your ProtocolCodecFilter
in the filter chain.

> What if I write using the IoSession.write(Object) in Decoder1 and just
> return need more data afterwards, this should bypass Decoder2, shouldn't
> it?

Yes, it should. You just have to make sure that Decoder1.decodable()
returns OK in this case, not NEED_DATA. (Of course, Decoder1.decode()
should return NEED_DATA).

> Is the ByteBuffer received by the 2nd decoder a new ByteBuffer?

In this case Decoder2 will never see the ByteBuffer (its decodable() may
be called if Decoder2 was added prior to Decoder1 to your
DemuxingProtocolCodecFactory).

Have a look at the method doDecode() in the inner class named
ProtocolDecoderImpl in DemuxingProtocolCodecFactory.

> 
> Also when writing to the IoSession, it will then go through the chain of
> encoders, right? Is there a way to bypass the encoders? Or should I
> implement some code in my encoders to just forward to the next encoder
> without doing any processing?

Just like with decoders there is no chain of encoders.
DemuxingProtocolCodecFactory will pick the encoder which matches the
message type and only use that. No other encoders will be used. If no
matching encoder can be found an exception will be thrown.

When writing ByteBuffers from your IoHandler, ProtocolCodecFilter will
automatically bypass the encoder since the messages already are ByteBuffers.

> I assume that if message1 and message2 are read by IoSession, message1
> will go through all the filters before message2 so the order of arrival
> is preserved. Am I correct?

Yes, MINA always preserves the ordering of received and sent messages.

/Niklas

Reply via email to