Simultaneous invocation of handlers
Frederic Bregier
fredbregier at free.fr
Mon Oct 19 04:03:45 EDT 2009
Hi Dan,
Each variables that are a member of the handler is visible each time it is
recalled for a new message.
So the reason to create a new handler for a one-based channel handler,
because if not, the same handler and so the same member variables will be
shared among all channels.
HTH,
Cheers,
Frederic
Dan D wrote:
>
> Thanks, that's helpful. I was most interested in (3), a stateful Handler
> that's created per-channel with no ExecutionHandler. It sounds like in
> this
> case I can assume that there will only be one outstanding Channel event at
> a
> time, and that all events will happen in order. That makes sense; keeping
> state right in a per-channel, stateful handler would get complicated if
> events could happen simultaneously.
>
> Are there any visibility guarantees across invocations of Handlers? E.g.
> if
> I handle an event in my per-Channel handler and change a member variable
> of
> the Handler, will that change be visible when the same Handler instance is
> invoked for the next event in a different thread?
>
> Date: Sun, 18 Oct 2009 00:37:46 -0700 (PDT)
>> From: Frederic Bregier <fredbregier at free.fr>
>> Subject: Re: Simultaneous invocation of handlers
>> To: netty-users at lists.jboss.org
>> Message-ID: <1255851466682-3843496.post at n2.nabble.com>
>> Content-Type: text/plain; charset=us-ascii
>>
>>
>> Hi Dan,
>>
>> It depends on the way you wrote your handler:
>>
>> 1) If you create only one Handler for any connected Channel (so not using
>> a
>> ChannelPipelineFactory, and if using it not creating a new handler as
>> business handler - generally the last one): then any connected channel
>> can
>> send a message and thus giving two messageReceived calls at the same
>> time,
>> except if an OrderedMemoryAwareThreadPoolExecutor is added in the
>> pipeline.
>>
>> 2) If you have one handler by channel but using a
>> MemoryAwareThreadPoolExecutor, then for one client, if two sends occur,
>> it
>> may lead to two messageReceived at the same time (note the "may" since
>> I'm
>> not totally sure, what I'm sure is that message can arrive in any order
>> like
>> the API says).
>>
>> 3) If you have one handler by channel and you don't use any
>> MemoryAwareThreadPoolExecutor or if one is used it is the Ordered one,
>> then
>> message will arrived in order and one by one for this handler (= one
>> channel). (Note that the OrderedMemoryAwareThreadPoolExecutor is not
>> necessary to get this behaviour).
>>
>> 4) If you have an handler shared among all connected channel but you use
>> a
>> OrderedMemoryAwareThreadPoolExecutor in the pipeline before this handler,
>> then the order is respected for at least one channel, but still two
>> channels
>> can received each one a message at the same time.
>>
>> So first it depends on if your logic is to have one handler for all
>> channel,
>> or one handler by channel.
>> Then try to follow those guidelines (note they are not official, just
>> mines,
>> they surely exist other ways ;-)
>>
>> Cheers,
>> Frederic
>>
>>
>> Dan D wrote:
>> >
>> > Say I've got a ChannelHandler that acts upstream of the the HTTP code
>> > handlers. Within messageReceived() I'm handling an HTTP request.
>> While
>> > I'm in messageReceived(), can messageReceived be invoked *for the same
>> > Channel* in another thread (a pipelined HTTP request comes in on the
>> same
>> > connection while I'm still processing the first one)? Or will the
>> second
>> > messageReceived() not be invoked until the first completes?
>> >
>> > Thanks.
>> >
>> > _______________________________________________
>> > netty-users mailing list
>> > netty-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/netty-users
>> >
>> >
>>
>>
>> -----
>> Hardware/Software Architect
>> --
>> View this message in context:
>> http://n2.nabble.com/Simultaneous-invocation-of-handlers-tp3842471p3843496.html
>> Sent from the Netty User Group mailing list archive at Nabble.com.
>>
>>
>>
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
>
-----
Hardware/Software Architect
--
View this message in context: http://n2.nabble.com/Simultaneous-invocation-of-handlers-tp3842471p3847714.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list