netty/netty — pull request #1999 by trustin (2013-11-22 11:00:23+00:00)
Title: ChannelHandler type hierarchy simplification

This changeset moves all methods in `ChannelInboundHandler` and `ChannelOutboundHandler` up to `ChannelHandler` and deprecate them and their adapters, greatly simplifying the type hierarchy of handlers by removing the distinction between 'inbound' handlers and 'outbound' handlers.

Because all handlers are now both inbound and outbound handlers, it is not reasonable to provide `CombinedChannelDuplexHandler`, whose purpose was to combine an inbound handler and an outbound handler into a single handler. Instead, I added a new handler called `ChannelHandlerAppender`, which appends the specified set of handlers together when it's added to the pipeline.

It also introduces an annotation called `@Passthrough` so that `DefaultChannelHandler` skips the evaluation of the handler methods annotated with `@Passthrough`. All handler methods in `ChannelHandlerAdapter` are annotated with `@Passthrough`, so extending `ChannelHandlerAdapter` will ensure that unoverridden methods are always annotated with `@Passthrough`. (i.e. most users don't need to know about this annotation unless they override a handler method and reverts back to pass-through mode.)

Thanks to the `@Passthrough` annotation, we can safely skip the evaluation of many unoverridden handler methods.

Because the inspection of the presence of the annotation relies on reflection, I introduced a simple cache in `DefaultChannelHandlerContext`. Is uses a partitioned synchronized `WeakHashMap` so I'd say it has a room for improvements, but at the moment, I wouldn't do premature optimization.

Talking about performance, I see slight boost, although it's not very noticeable. (0.5~1k HTTP QPS in my laptop)

This pull request is not complete yet - I'll clean all deprecation warnings and some rough edges soon.