Getting variables from/ Handlers

Bruno Mello bruno.mello at sapo.pt
Thu Mar 11 20:12:21 EST 2010


Hey again,

After trying a bit harder I did it (don't know if using the best way,
though).

Since another user posted a question similar to mine some days ago (08/Mar)
I'll detail my solution.

I wanted the general "send" in the MWServer class, so I added a private
variable and a constructor and instantiated the MWServerHandler there
(variable mwsh). The mwsh was passed to the MWServerPipelineFactory. To do
so, I had to create a private variable and constructor there too, because
the addLast("handler", ) method appeared in the getPipeline().

Finally I modified the MWServerHandler to maintain an ArrayList of
ChannelHandlerContext. Everytime a connection is established (I overwritten
the channelConnected() method) the ctx parameter is added to the ArrayList.

In the MWServerHandler I had to add the getCtxs() method to return the
ArrayList and in the MWServer I created the intended send() method which
gets the list and broadcasts a message.

I had to add 2 constructors and 2 local class variables but it works. I
think I got trouble reaching this solution because the Netty examples are
too compact and for some Java developers with less experience it might be
difficult to understand how things fit together.

Anyway, I'm still looking forward for some expert opinion on my solution.

Thank you all.
-- 
View this message in context: http://n2.nabble.com/Getting-variables-from-Handlers-tp4719574p4719805.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list