Channel attachments?
Norman Maurer
norman at apache.org
Fri Jun 11 03:16:23 EDT 2010
I think thats a problem many people hit. I fixed it by using a static
instance of ChannelLocal which was put in an Interface. This interface
get implemented by all Handlers which needs to pass Attachments to
each other. Not elegant, but it works. I would prefer to have some
kind of getter/setter for it in the ChannelHandlerContext.
Here you can see how I did it:
http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/ChannelAttributeSupport.java?view=markup
http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelUpstreamHandler.java?view=markup
Hope it helps,
Norman
2010/6/11 Marc-André Laverdière <marcandre.laverdiere at gmail.com>:
> Hello,
>
> I hit something like that in my development efforts. I was trying to
> put the session ID using the attachment, and that wasn't working in my
> app... I'd get a null when I expected a String.
>
> So I created a global object that wraps around a ChannelLocal and my
> handlers refer to it to get the session ID.
>
> Hardly a cute design, but it works.
>
> The attachment feature in ChannelHandlerContext should be this wrapper
> around a ChannelLocal and should be enough for everybody's needs.
> Maybe that is what its meant to be but there is a bug, I don't know (I
> haven't looked at the code).
>
> What I would find nice is that we could use generics so that we're not
> stuck casting from Object and cross our fingers that nobody else in
> the dev team broke the pipeline or something...
>
> Marc-André LAVERDIÈRE
> "Perseverance must finish its work so that you may be mature and
> complete, not lacking anything." -James 1:4
> mlaverd.theunixplace.com/blog
>
> /"\
> \ / ASCII Ribbon Campaign
> X against HTML e-mail
> / \
>
>
> 2010/6/11 blakeman8192 <blakeman8192 at hotmail.com>
>>
>> I've used MINA, which was made by the same developer.
>>
>> MINA used to have setAttachment(Object) and getAttachment() methods, then
>> later got setAttribute(String, Object) and getAttribute(String) methods.
>> These are really convenient.
>>
>> Netty doesn't seem to have any methods of the sort for Channel.
>>
>> I know that Netty has setAttachment(Object) and getAttachment() for a
>> ChannelHandlerContext, but in the server I'm developing, there are different
>> decoders that replace each other. I need some way to keep track of
>> attributes for a Channel, not a ChannelHandlerContext because the
>> ChannelHandlerContexts do change so what I attach to one will not be a part
>> of another.
>>
>> I've noticed ChannelLocal, but there is no method to get a ChannelLocal
>> object for a Channel. It also seems pretty redundant to use a Map<Channel,
>> ChannelLocal> to keep track of ChannelLocal objects for Channels.
>>
>> I need a more elegant way to keep track of different objects (i.e. a Player
>> object) for a Channel.
>> Is this overlooked in the Netty design, or (more likely) am I missing
>> something?
>>
>> Thanks for your time,
>> -Blake
>> --
>> View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Channel-attachments-tp5165235p5165235.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
>
> _______________________________________________
> 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