Q:

Store variables on netty TCP Connection

I need to store an Object for later usage on a TCP connection on NETTY. After user login, some variables need to be stored on this user connection.
What's the proper way to do it? I tried storing some variables on ChannelHandler Context(), but this is deprecated:
public void channelRegistered(ChannelHandlerContext ctx)
{
    ctx.attr(attrObj).set(new Session(ctx));
}

Then I tried storing on channel:
public void channelRegistered(ChannelHandlerContext ctx)
{
    ctx.channel().attr(attrObj).set(new Session(ctx));
}

The object was shared with all TCP Sessions, so no success.
How can I set my Session() object on this specific TCP user connection, so all next messages from this user, can retrieve this data easily?
Thanks

A:

Just use ctx.channel().attr(attrObj).set(...) as you did. Each channel has different attributes and so it is per connection. If there are multiple sessions per TCP connection you will need to put it in a map that is stored as attribute on the Channel.

