Problem of hundreds ChannelHandler for one connection

Marc-André Laverdière marcandre.laverdiere at gmail.com
Thu May 12 04:36:36 EDT 2011


I have never pushed Netty to that level, so I'm afraid I don't have an answer.

I will tell you how I am using it, by ways of a pipeline

socket -> traffic monitor -> SSL Handler -> Frame decoder (length
prefix) -> protobuf decoder (convert the message to a protobuf object)
-> MATPE -> handler

You can reverse the thing (+ s/decoder/encoder) for outgoing messages.

As far as I understand, this would be "the right way" to use Netty,
but I could be wrong :)

Now, in your case, you are trying to put application-level events in
your network layer. I don't think it is a great idea because it brings
pretty insane coupling.

That being said, you can extend the event type to create more events,
and create handlers that know how to handle them. You won't be able to
use readymade ones from netty (channel closed events and the like),
but you can always 'switch' between the possible types in an
ChannelUpstreamHandler.handleUpstream.

The way you could do this is along those lines:

if (e instanceof MyEvents){
  switch (((MyEvents)e).getType){
    case ATTACK: ...
    break;
    ...
  }
} else
  super.handleUpstream(...)

Just my 2 paisa :)

On 5/12/11, magiceye <magiceye at 163.com> wrote:
> Indeed I'm misunderstand the 'event' in netty. ChannelEvent used to describe
> general concept event in communication. The minimal granularity is 'message
> arrived', it is impossible to do more such as 'what the message type is
> which I defined'.
>
> But there is a sentence copy from netty user guide in section 2.3 :
> "Well-defined and extensible event model is a must for an event-driven
> application. Netty does have a well defined event model focused on I/O. It
> also allows you to implement your own event type without breaking the
> existing code at all because each event type is distinguished from each
> other by strict type hierarchy. This is another differentiator against other
> frameworks. Many NIO frameworks have no or very limited notion of event
> model; they often break the existing code when you try to add a new custom
> event type, or just do not allow extension."
>
> what the meaning of 'your own event type'? It seems netty can support
> user-define message event dispatcher. But how? Derive from 'MessageEvent' to
> make myself message event such as "AttackEvent"? But messageReceived's
> parameter type is MessageEvent, no way to dispatch those 'new event type'
>
> --
> View this message in context:
> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Problem-of-hundreds-ChannelHandler-for-one-connection-tp6343673p6354614.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
>


-- 
Marc-André LAVERDIÈRE
"Perseverance must finish its work so that you may be mature and complete,
not lacking anything." -James 1:4
http://asimplediscipleslife.blogspot.com/
mlaverd.theunixplace.com



More information about the netty-users mailing list