passing data between ChannelHandlers

Norman Maurer norman.maurer at googlemail.com
Sun Oct 16 14:48:11 EDT 2011


With the Context Attachment you can use a singleton of your Handler.
So you don't need to create to many objects....

See also:
http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/ChannelHandler.html

Bye,
Norman


2011/10/16 Matt DeLuco <list_usr at spacebox.net>:
> What's the purpose of a context attachment visible only within the same
> handler?
> Couldn't member variables achieve the same thing?
> MD
>
> On Sun, Oct 16, 2011 at 7:14 AM, Norman Maurer
> <norman.maurer at googlemail.com> wrote:
>>
>> You can set anything you want as attachment. But it's only visible in
>> the same handler....
>>
>> If you want to share stuff between handler you should checkout
>> ChannelLocal
>>
>> Bye
>> Norman
>> 2011/10/16, Matt DeLuco <list_usr at spacebox.net>:
>> > Before composing this message I had noticed
>> > ChannelHandlerContext.setAttachment(Object) and getAttachment().  But
>> > for some reason I came to the conclusion that it wasn't intended for
>> > what I want to do.
>> >
>> > I came to that conclusion in part because I found it strange that it's
>> > only possible to set one attachment, rather than being able to attach
>> > a set (or map) of objects.  Could I just attach a map to the context
>> > and store whatever I want in that map, to pass objects between
>> > ChannelHandlers?
>> >
>> > MD
>> >
>> >
>> > On Sat, Oct 15, 2011 at 9:42 PM, Matt DeLuco <list_usr at spacebox.net>
>> > wrote:
>> >> Is it possible to pass data between ChannelHandlers, or store data
>> >> somewhere that the handlers in a specific pipeline/channel can access
>> >> throughout the lifetime of the request?
>> >>
>> >> For example, I have my own class for dealing with http cookies,
>> >> "CookieMap".  I'd like to have a SimpleChannelHandler that creates a
>> >> CookieMap to be used by handlers further upstream, and then sets the
>> >> cookies in the CookieMap on the response on their way back downstream.
>> >>
>> >> MD
>> >>
>> >
>> > _______________________________________________
>> > netty-users mailing list
>> > netty-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/netty-users
>> >
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
>
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>



More information about the netty-users mailing list