Getting variables from/ Handlers

Christian Migowski chrismfwrd at gmail.com
Fri Mar 12 02:53:38 EST 2010


Hello Bruno,

in my opinion you've got the main idea right (but you should store
Channels not the contexts). However, you should have a look at
ChannelGroup, which already handles things you still would have to
implement in your "home-grown" solution (removing closed channels).
The Netty Javadoc is fantastically detailed, there are lots of
examples in it.

hope this helps,
regards,
christian!

On Fri, Mar 12, 2010 at 2:12 AM, Bruno Mello <bruno.mello at sapo.pt> wrote:
>
> 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.
> _______________________________________________
> 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