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 22:25:30 -0700

Hi,

> So it is expected behavior that:
> A new FilterChainContext was created when new message came in.
right, FilterChainContext is associated with the specific packet processing.

> Different connection share the same Filter instance, and Filter is
> somehow singleton.
correct, normally Filters and FilterChain are stateless objects, so they
can be reused for different Connections.

Thanks.

WBR,
Alexey.

>
> Regards
> LongkerDandy
>
>
> On Fri, Jun 13, 2014 at 11:43 AM, Oleksiy Stashok
> <oleksiy.stashok_at_oracle.com <mailto:oleksiy.stashok_at_oracle.com>> wrote:
>
> 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
>
>