per session attributes

falconair shahbazc at gmail.com
Mon Mar 8 23:57:31 EST 2010


Hi Trustin,
I've come across the need to access session variables again.  Wouldn't it be
cleaner to add a Map to the context object?

In other words, in any handler, I could do the following:
...
String myvar = ctx.getEnvironment("myvar");
...
ctx.setEnvironment("myvar2","sessionID123");
...

I naturally keep expecting the context to provide such a
functionality--variables set in one handler can be accessed by subsequent
handlers.


Trustin Lee wrote:
> 
> Hi falconair,
> 
> myAttr (i.e. a ChannelLocal instance) is supposed to be accessible from
> any handlers, so I would expose it as a public static final member
> variable of some class.  For example:
> 
>     public class MyChannelAttrs {
>         public static final ChannelLocal<String> myAttr = ...;
>     }
> 
> HTH,
> Trustin
> 
> falconair wrote:
>> I am trying to figure out how to set variables per connection.  Once a
>> client
>> connects to my server, they send a log on message with some attributes. 
>> I'd
>> like to make those attributes available to every filter/handler in my
>> pipeline.
>> 
>> Previous messages in the mailing list point to ChannelLocal, such as the
>> following example:
>> 
>> final ChannelLocal<String> myAttr = new ChannelLocal<String>(); 
>>   ... 
>>   String a = myAttr.get(channel); 
>>   myAttr.set(channel, "newValue"); 
>>   myAttr.remove(channel); 
>> 
>> But I'm not sure how to use it exactly.  Am I supposed to 'put' myAttr in
>> the ChannelHandlerContext?  In other words, say my logon handler
>> retrieves
>> my attribute, how do I make it available to subsequent handlers?
>> 
>> Thanks
> 
> 
>  
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
> 
> 
-- 
View this message in context: http://n2.nabble.com/per-session-attributes-tp4219656p4700324.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list