You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Steven E. Harris" <se...@panix.com> on 2007/01/09 18:17:10 UTC

IoSession-level synchronization of ProtocolEncoder/ProtocolDecoder pair

I'm using a ProtocolEncoder and ProtocolDecoder pair supplied to a
ProtocolCodecFilter, and am wondering whether the
ProtocolEncoder.encode() and ProtocolDecoder.decode() methods will
ever be called on concurrently for the same IoSession. That is, is it
possible that an encoder is writing at the same time a decoder is
reading?

The question arises because the network protocol permits
pipelining. The decoder side may see an error signaled by its peer,
and wish to notify the encoder side to stop writing requests on this
connection/session; hence the encoder and decoder communicate. Should
I assume that this communication between encoder and decoder may be
happening between separate threads, or can I assume that the encoder
and decoder are never used concurrently, at least for a given
IoSession?

-- 
Steven E. Harris

Re: IoSession-level synchronization of ProtocolEncoder/ProtocolDecoder pair

Posted by Trustin Lee <tr...@gmail.com>.
On 1/16/07, Maarten Bosteels <mb...@gmail.com> wrote:
>
> On 1/16/07, Trustin Lee <tr...@gmail.com> wrote:
> > Hi Steven,
> >
> > On 1/10/07, Steven E. Harris <se...@panix.com> wrote:
> > >
> > > I'm using a ProtocolEncoder and ProtocolDecoder pair supplied to a
> > > ProtocolCodecFilter, and am wondering whether the
> > > ProtocolEncoder.encode() and ProtocolDecoder.decode() methods will
> > > ever be called on concurrently for the same IoSession. That is, is it
> > > possible that an encoder is writing at the same time a decoder is
> > > reading?
> >
> >
> > Yes. (Related thread: *http://tinyurl.com/ygazu9)*
> >
> > The question arises because the network protocol permits
> > > pipelining. The decoder side may see an error signaled by its peer,
> > > and wish to notify the encoder side to stop writing requests on this
> > > connection/session; hence the encoder and decoder communicate. Should
> > > I assume that this communication between encoder and decoder may be
> > > happening between separate threads, or can I assume that the encoder
> > > and decoder are never used concurrently, at least for a given
> > > IoSession?
> >
> >
> > IoSession.write() can be invoked from any thread, so you will need some
> kind
> > of inter-process communication in you IoHandler and writer thread.  I
> think
>
> shouldn't that be "inter-thread communication" ?


You're right.  My bad!

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: IoSession-level synchronization of ProtocolEncoder/ProtocolDecoder pair

Posted by Maarten Bosteels <mb...@gmail.com>.
On 1/16/07, Trustin Lee <tr...@gmail.com> wrote:
> Hi Steven,
>
> On 1/10/07, Steven E. Harris <se...@panix.com> wrote:
> >
> > I'm using a ProtocolEncoder and ProtocolDecoder pair supplied to a
> > ProtocolCodecFilter, and am wondering whether the
> > ProtocolEncoder.encode() and ProtocolDecoder.decode() methods will
> > ever be called on concurrently for the same IoSession. That is, is it
> > possible that an encoder is writing at the same time a decoder is
> > reading?
>
>
> Yes. (Related thread: *http://tinyurl.com/ygazu9)*
>
> The question arises because the network protocol permits
> > pipelining. The decoder side may see an error signaled by its peer,
> > and wish to notify the encoder side to stop writing requests on this
> > connection/session; hence the encoder and decoder communicate. Should
> > I assume that this communication between encoder and decoder may be
> > happening between separate threads, or can I assume that the encoder
> > and decoder are never used concurrently, at least for a given
> > IoSession?
>
>
> IoSession.write() can be invoked from any thread, so you will need some kind
> of inter-process communication in you IoHandler and writer thread.  I think

shouldn't that be "inter-thread communication" ?

Maarten

> decoder is not a good place to detect a problem.  I'd rather use
> exceptionCaught() handler.  You can filter exceptions from a decoder very
> easily because all exceptions thrown by a decoder will be wrapped by
> ProtocolDecoderException.
>
> 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: IoSession-level synchronization of ProtocolEncoder/ProtocolDecoder pair

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

On 1/10/07, Steven E. Harris <se...@panix.com> wrote:
>
> I'm using a ProtocolEncoder and ProtocolDecoder pair supplied to a
> ProtocolCodecFilter, and am wondering whether the
> ProtocolEncoder.encode() and ProtocolDecoder.decode() methods will
> ever be called on concurrently for the same IoSession. That is, is it
> possible that an encoder is writing at the same time a decoder is
> reading?


Yes. (Related thread: *http://tinyurl.com/ygazu9)*

The question arises because the network protocol permits
> pipelining. The decoder side may see an error signaled by its peer,
> and wish to notify the encoder side to stop writing requests on this
> connection/session; hence the encoder and decoder communicate. Should
> I assume that this communication between encoder and decoder may be
> happening between separate threads, or can I assume that the encoder
> and decoder are never used concurrently, at least for a given
> IoSession?


IoSession.write() can be invoked from any thread, so you will need some kind
of inter-process communication in you IoHandler and writer thread.  I think
decoder is not a good place to detect a problem.  I'd rather use
exceptionCaught() handler.  You can filter exceptions from a decoder very
easily because all exceptions thrown by a decoder will be wrapped by
ProtocolDecoderException.

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