ChannelPipeline question

Frederic Bregier fredbregier at free.fr
Tue Sep 1 12:03:25 EDT 2009


Hi Mike,

First, "all" is right now only an annotation, so no error will come if you
write "one" or "all" in your handler. It is only an help for a reader who is
not the writer ;-)

Now, if your handler is a stateful but you do take into account concurrency
(for instance which channel is using currently the handler by the id of the
channel), it should be ok. 
Take care it is not only about concurrent access, it greatly depends on what
the handler has to do and what kind of "persistent" information for each
channel it has to keep in memory. 
For instance, let say we try to write the StringDecoder using an "all"
method, this would implied to have as many current channelBuffer as channels
in one handler. This could be somewhat complicated, also doable. It is
obviously simpler (in term of development) for this case to use one "one"
version with a new created handler for each channel.

If the handler has only small info to store for each channel, then
implementing such a "all" handler but using a stateful logic can have a
sens. For instance, if some information have to be shared among all channels
in the handler (stateful but also considering several channels for
instance), then you can try an "all" version, also you can also try an "one"
version using some shared data object.
 
My opinion (only mine ;-) is that a stateful handler most of the time should
be a "one" version, but as usual, many exceptions can exist! I don't have in
mind one real example, but I'm sure there are a lot.
If you can share a description of your example, it could help perhaps some
users (like me) to go further?

HTH,
Cheers,
Frederic


Mike McGrady wrote:
> 
> Just a more detailed thought, Fredric, on this matter.  I think you  
> can use "all" with stateful handlers so long as the state is handled  
> consistent with concurrent access.  I do this with my first Netty  
> application, if I am understanding you correctly.  What do you think?
> 
> Mike
> 
> 
> On Sep 1, 2009, at 3:32 AM, Frederic Bregier wrote:
> 
>>
>> Hi Mike,
>>
>> If I made some mistake, please correct me of course ;-)
>>
>> "all" means that several channels can shared this handler (stateless).
>> "one" means that this handler is for one and only one channel  
>> (stateful).
>>
>> bootstrap.getPipeline() => if you add handlers there, they should be  
>> "all"
>> since the pipeline will be shared by all channels that will connect  
>> or be
>> connected through this bootstrap.
>>
>> In a ChannelPipelineFactory, you can mixed "all" and "one" handlers.  
>> For
>> instance, if you have a handler that can be shared among all  
>> channels, then
>> even included from the factory, it could be "all". On the opposite,  
>> usualy
>> you have at least 1 handler that is "one" in such a construction  
>> (generally
>> the codecd that is a stateful one).
>> The pipeline will be new for each new channel, but the handlers you  
>> put in
>> it can be shared (statically created in the Factory and reused so  
>> "all") or
>> unique by channel (created in the getPipeline() method so "one").
>> If all handlers are "all", then I think it is better to use the  
>> bootstrap
>> version since there will be only one Pipeline shared among all  
>> channels with
>> the same handlers. But if you have at least one "one" handler  
>> (stateful),
>> then it is preferable to use the ChannelPipelineFactory.
>>
>> Or you can added it at runtime (in channelConnected for instance)  
>> manually.
>> Again, the added handler can be "all" (static and reused) or  
>> "one" (new one
>> created).
>> I feel like, even if it is correct, it somehow less easy to read  
>> such a code
>> since the we don't know where such handlers are added or not. But in  
>> some
>> occasion, you don't have the choice (for instance, a new handler is  
>> needed
>> once the channel is connected for some specific behaviour).
>>
>> HTH,
>>
>> Cheers,
>> Frederic
>>
>>
>> MikeQ wrote:
>>>
>>> Hi all,
>>>
>>> Quick q about @ChannelPipelineCoverage and setup of handlers.
>>>
>>> As far as I can tell when setting up a new pipeline you have a  
>>> couple of
>>> options.
>>>
>>> - Adding handlers using bootstrap.getPipeline()
>>>    - I believe in this instance all the handlers are singletons (one
>>> shared by all channels) and must therefore be
>>> @ChannelPipelineCoverage("all")
>>>
>>> - Adding handlers using a ChannelPipelineFactory
>>>    - I believe the ChannelPipelineFactory.getPipeline() is called for
>>> each new channel.  The handlers can therefore be one/all depending on
>>> whether the getPipeline() implementation creates a new instance  
>>> each time
>>> (one) or uses a shared instance (all)
>>>
>>> - Adding handlers during execution of another handler
>>>    - Similar to ChannelPipelineFactory in that a new instance or  
>>> shared
>>> instance can be used
>>>
>>> If someone could confirm/correct the above that would be useful for  
>>> my own
>>> understanding.
>>>
>>> Cheers.
>>>
>>
>>
>> -----
>> Hardware/Software Architect
>> -- 
>> View this message in context:
>> http://n2.nabble.com/ChannelPipeline-question-tp3559391p3559650.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
> 
> Mike McGrady
> Principal Investigator AF081-028 AFRL SBIR
> Senior Engineer
> Topia Technology, Inc
> 1.253.720.3365
> mmcgrady at topiatechnology.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/ChannelPipeline-question-tp3559391p3561483.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list