You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Emmanuel Lecharny <el...@apache.org> on 2009/07/16 11:24:12 UTC

Re: How I use more than one codec filter with one acceptor

You can't use two codec filters in the chain, due to the way the data
are passed from one filter to another one (we use IoBuffer for that).

This will be modified in 3.0, but don't expect this version to be out soon.

In the mean time, the only option is to wrap the textline codec into
the JSON codec. Not that easy, but not that complex too.

On Thu, Jul 16, 2009 at 7:04 PM, elf.cheng<el...@browan.com> wrote:
>
>        I'am using a JSON based Protcol in my server program based on
> mina.To
> deal with json string,I write  codecs to decode from string or
> encode to string.I used this codecfactory like the following:
>         acceptor.getFilterChain().addLast("logger", new
> LoggingFilter());
>      acceptor.getFilterChain().addLast("codec_txt", new
> ProtocolCodecFilter(new
> TextLineCodecFactory(Charset.forName("UTF-8"))));
>       acceptor.getFilterChain().addLast("codec_json", new
> ProtocolCodecFilter(new JsonCodecFactory()));
>
>        but the filter "codec_json" dose not work! who can tell me why?
>
> elf.cheng
>
>



-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: How I use more than one codec filter with one acceptor

Posted by Emmanuel Lecharny <el...@apache.org>.
On Thu, Jul 16, 2009 at 11:24 AM, Emmanuel Lecharny<el...@apache.org> wrote:
> You can't use two codec filters in the chain, due to the way the data
> are passed from one filter to another one (we use IoBuffer for that).

This is plain BS, now that I had time to check on the code.

MessageReceived() method manipulates an Object, not an IoBuffer.

Sorry for the confusion.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: How I use more than one codec filter with one acceptor

Posted by Ashish <pa...@gmail.com>.
On Thu, Jul 16, 2009 at 7:51 PM, Emmanuel Lecharny<el...@apache.org> wrote:
> Sorry, Ashish, after having refreshed my memory by looking at the
> code, just discard what I have said.
>
> MessageReceived() get an Object as a parameter, not a IoBuffer. So as
> soon as you *know* what type the message type is, it should be plain
> ok.
> Sorry for the confusion.

Ok, so the chain (Filter A - Protocol Decoder B - Filter C) is possible :-)


-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Re: How I use more than one codec filter with one acceptor

Posted by Emmanuel Lecharny <el...@apache.org>.
Sorry, Ashish, after having refreshed my memory by looking at the
code, just discard what I have said.

MessageReceived() get an Object as a parameter, not a IoBuffer. So as
soon as you *know* what type the message type is, it should be plain
ok.

Sorry for the confusion.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: How I use more than one codec filter with one acceptor

Posted by Ashish <pa...@gmail.com>.
On Thu, Jul 16, 2009 at 3:36 PM, Emmanuel Lecharny<el...@apache.org> wrote:
> On Thu, Jul 16, 2009 at 11:58 AM, Ashish<pa...@gmail.com> wrote:
>> On Thu, Jul 16, 2009 at 2:54 PM, Emmanuel Lecharny<el...@apache.org> wrote:
>>> You can't use two codec filters in the chain, due to the way the data
>>> are passed from one filter to another one (we use IoBuffer for that).
>>
>> Can IoFilter be used in these situations?
> No, not with the current API? This is one of the major problem we have
> with the use of IoBuffer - beside other problems - and this is the
> reason we want to replace it with a kind of Stream API, where the
> Stream will be able to carry Objects instead of IoBuffers. This would
> make it simple then the chain two codecs, one accepting byte[] and
> transforming it to a type T, the second one accepting T objects and
> transforming them to a type U, etc. The first codec filter will use a
> Stream<byte[]> and produce a Stream<T>, the second codec will accept a
> Stream<T> and produce a Stream<U>.
>
> Of course, this has to be elaborated, but I guess you get the idea.

Got it. All the way I thought I could build a chain this way  :-(

>
>> Can a filter chain look something like this
>>
>> IoFilter A (Logging Filter) -- Protocol Decoder B - IoFilter C
>
> AFAIR, from the top of my head ( I don't have access to the code right
> now), no.

-- 
thanks
ashish

Re: How I use more than one codec filter with one acceptor

Posted by Emmanuel Lecharny <el...@apache.org>.
On Thu, Jul 16, 2009 at 11:58 AM, Ashish<pa...@gmail.com> wrote:
> On Thu, Jul 16, 2009 at 2:54 PM, Emmanuel Lecharny<el...@apache.org> wrote:
>> You can't use two codec filters in the chain, due to the way the data
>> are passed from one filter to another one (we use IoBuffer for that).
>
> Can IoFilter be used in these situations?
No, not with the current API? This is one of the major problem we have
with the use of IoBuffer - beside other problems - and this is the
reason we want to replace it with a kind of Stream API, where the
Stream will be able to carry Objects instead of IoBuffers. This would
make it simple then the chain two codecs, one accepting byte[] and
transforming it to a type T, the second one accepting T objects and
transforming them to a type U, etc. The first codec filter will use a
Stream<byte[]> and produce a Stream<T>, the second codec will accept a
Stream<T> and produce a Stream<U>.

Of course, this has to be elaborated, but I guess you get the idea.

> Can a filter chain look something like this
>
> IoFilter A (Logging Filter) -- Protocol Decoder B - IoFilter C

AFAIR, from the top of my head ( I don't have access to the code right
now), no.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Re: How I use more than one codec filter with one acceptor

Posted by Ashish <pa...@gmail.com>.
On Thu, Jul 16, 2009 at 2:54 PM, Emmanuel Lecharny<el...@apache.org> wrote:
> You can't use two codec filters in the chain, due to the way the data
> are passed from one filter to another one (we use IoBuffer for that).

Can IoFilter be used in these situations?

Can a filter chain look something like this

IoFilter A (Logging Filter) -- Protocol Decoder B - IoFilter C

Where Protocol Decoder B - transforms binary message into High Level Object
IoFilter C - translates High Level Object from B into another
representation, say object ABC

>
> This will be modified in 3.0, but don't expect this version to be out soon.
>
> In the mean time, the only option is to wrap the textline codec into
> the JSON codec. Not that easy, but not that complex too.
>