On 9/30/06, oscar 12321 <[EMAIL PROTECTED]> wrote:
>>
>>I have a complex protocol to implement and I have started modifying the
>>sumup example.
>>
>>My protocol consists of messages all of then sent in and envelope like
>>this:
>>
>>4 bytes: size of data
>>N bytes: the data
>>1 byte: tail mark.
>>
>>Then each message inside the envelope (the data), contains a header byte
>>with the type of message flllowed by the rest of fields of the message.
>>
>>My question is: should i implement a stack of two protocol filters, one
>>for
>>the envelope (like the TextLineCodec), and other for the message data
>>itself
>>(perhaps a DemuxingProtocolCodec)?
>
>
>You just need one codec and one custom filter instead of two codecs:
>
>1. Codec translates the message into an intermediary message.
>2. Your filter translates the intermediary message (the data, envelope)
>into
>the final message object.
>
>Implementing a filter is very easy, so you will be able to implement the
>translator shortly.
>
>...
>void messageReceived(NextFilter next, IoSession session, Object message)
{
> IntermediaryMessage m = (IntermediaryMessage) message;
> ByteBuffer buf = m.getContent();
> ... do something with the buf ...
> next.messageReceived(session, newMessage);
>}
>...
>
>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
Hi Trustin,
I have done it and its working for the received messages, but when i whant
to send a message, the filter is ignored and goes directly to the codec.
It
seems that the chain is working well for received messages but not for
outgoing ones.
I create the chain in the session handler like this:
ProtocolCodecFactory codec = MyCodecFactory(); // The envelope codec
factory
session.getFilterChain().addFirst("protocolFilter", new
ProtocolCodecFilter(codec));
session.getFilterChain().addLast("messageFilter", new MessageFilter());
The codec is working well by removing or adding the envelope, but the
filter
is only working for received messages.
I have suibclassed it from "IoFilterAdapter" and override the
"messageReceived" and "messageSent". But "MessageSent" its never called,
instead the encoder is called directly.
Q1: Are you sure that you overrided filterWrite()?
Q2: Is IoHandler.messageSent() called then?
It would be the best if you can provide a reproduceable unit test to us.
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