Storing extra properties for each channel

Trustin Lee tlee at redhat.com
Sat Mar 21 10:20:15 EDT 2009


On Sat, Mar 21, 2009 at 4:37 PM, Frederic Bregier <fredbregier at free.fr> wrote:
> One possibility to store extra informations is using the attachement
> in one channelHandler in your pipeline (set/get Attachment).
> But this way is only valid if the channelHandler is unique for
> each channel (created using a ChannelPipelineFactory for instance
> and as a new object for each channel). If the handler is shared accross
> several channels, of course, the attachment is therefore shared
> accross several channels.

This is not true.  Attachment is not shared.  Moreover, if you add the
same handler instance to the same pipeline, you are given with two
handler contexts, and therefore you will have two attachments for the
handler.  If you added the same handler instance to the pipeline of
different channels, all of them will be given with its own handler
contexts, and therefore each of them will have its own attachment
space.

> I recall a remark of Trustin about storing directly an Object
> (real Object type) in channel directly (as in set/get Attachment in
> handlers),
> but I didn't find it again.

Check ChannelLocal. :)

HTH,

— Trustin Lee, http://gleamynode.net/




More information about the netty-users mailing list