Storing extra properties for each channel

Frederic Bregier fredbregier at free.fr
Sat Mar 21 03:37:28 EDT 2009


Hi,

I've got not all your answer but some of them or at least some points.
Trustin can certainly complete my view...

Yes the channel is automaticaly removed from the group when it is
disconnected (I was missing this, so thank you for pointing this ;-).

One possibility to store extra informations is using the attachement
in one channelHandler in your pipeline (set/get Attachment).
But this way is only valid if the channelHandler is unique for
each channel (created using a ChannelPipelineFactory for instance
and as a new object for each channel). If the handler is shared accross
several channels, of course, the attachment is therefore shared
accross several channels.
However, then, you will have to access to the pipeline, get back
the handler context from its name (getContext(name)) and 
then access to its attachment. 
This way could be not efficient since you will go accross several
objects, the map of context and so on.

Another way, which I feel simpler, is to create in your pipeline
as the last handler, your "business" handler, which must be created
also once for each channel (again in the factory or by hand).
Then, all your business actions will take care in this object
(end of the road from write or read operations) and you can add
a specific object (or several) that stores any information you need
for this particular channel. I used this way to store what I call
"session" object, which is a big object including all necessary
informations. 
This object is created in the channelConnected method and destroy in
the channelClosed method (same as in previous example with attachment).
With this method, you still have to handle this by hand, but you don't
have to go through a map, since it is a direct access.
However, it implies that you need a unique handler by channel somewhere
(preferably as the last one for business actions).

I recall a remark of Trustin about storing directly an Object
(real Object type) in channel directly (as in set/get Attachment in
handlers),
but I didn't find it again. 

Perhaps Trustin can explain the reason of why there is no such possibility
as in handlers ?

HTH,
Frederic

-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/Storing-extra-properties-for-each-channel-tp2511153p2512757.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list