users@grizzly.java.net

Re: Correct way to save state variable per connection

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Thu, 12 Jun 2014 20:43:54 -0700

Hi,

you can associate an Attribute with a Connection like:

     private final Attribute<*/AttrType/*> attribute =
Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(*/attributeNameString/*);
..........

     attribute.set(connection, /*value*/);
..........

     attribute.get(connection);
...........

     attribute.remove(connection);
............

WBR,
Alexey.


On 12.06.14 20:01, LongkerDandy wrote:
> Hi
>
> On TCP serevr side, I tried to save some state information per connection.
> Like the user id which already logged in.
> I'm trying use FilterChainContext.getAttributes().getAttribute and
> setAttribute.
> But seems I got a new FilterChainContext and new Filter instances
> everytime new message arrived.
> And my previous setted attributes are gone.
>
> So, what is the correct way to keep this state information?
>
> Regards
> LongkerDandy