best way to attach metadata to a channel
Norman Maurer
norman.maurer at googlemail.com
Thu Sep 22 01:41:36 EDT 2011
Hi there,
I think the best explaintation can be found here:
http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/ChannelHandler.html
Bye,
Norman
2011/9/22 Steve Coughlan <shadders.del at gmail.com>:
> I'm building a proxy for a binary protocol that will multiple chanels
> on either side. Each channel can be obtained either by a server or a
> client and once they are obtained I will treat them identically.
>
> I need to attach metadata to each channel that is easily accessable
> from the handler.messageReceived(ChannelHandlerContext ctx,
> MessageEvent e) method. My metadata class is NodeChannel and contains
> a reference to the channel itself.
>
> I'd prefer to avoid subclassing Channel as that then ties me to a
> particular transport implementation.
>
> It would seem the logical way is use
> ChannelHandlerContext.getAttachment but I am not entirely clear if
> there's a one to one relationship between ChannelHandlerContext and
> Channel. If I keep a reference to ChannelHandlerContext in
> NodeChannel rather than the channel can I garuntee that it's
> getChannel will always return the same channel object? And I can I
> garuntee that will only ever be one instance of ChannelHandlerContext
> that will return that channel?
>
> I'd really prefer to avoid doing a map lookup with channel as key to
> obtain the metadata. Many message will simply be ignored so this
> would be a serious waste of resources.
>
> Also can someone tell me when ctx is populated with a channel. I'm
> trying to obtain a reference within channelOpen but it's returning
> null at that stage.
> _______________________________________________
> 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