Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChannelHandler type hierarchy simplification #1999

Closed
wants to merge 1 commit into from
Closed

Conversation

trustin
Copy link
Member

@trustin trustin commented Nov 22, 2013

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 @Skip so that DefaultChannelHandler skips the evaluation of the handler methods annotated with @Skip. All handler methods in ChannelHandlerAdapter are annotated with @Skip, so extending ChannelHandlerAdapter will ensure that unoverridden methods are always annotated with @Skip. (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 @Skip 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) Simple distributed echo test on Mesos shows no regression (i.e. same latency/throughput. probably because it's just a single handler pipeline?)

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

@ghost
Copy link

ghost commented Nov 22, 2013

Build result for #1999 at 127a071: Success

* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/
void invokeWriteAndFlush(ChannelHandlerContext ctx, Object msg, ChannelPromise promise);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all handlers override both write() and flush(). Some will override only write() or only flush(). See the changes in DefaultChannelHandler.writeAndFlush(). What's your concern?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concern just was wondering why.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. :-)

@normanmaurer
Copy link
Member

@trustin another thing... I'm not sure the @Deprecation of ChannelInboundHandler and ChannelOutboundHandler is useful as implementations of those will break. This is because ChannelHandler now has all the methods included and so implementations of ChannelInboundHandler/ChannelOutboundHandler will not be complete..

@ghost
Copy link

ghost commented Nov 22, 2013

Build result for #1999 at 7d8fd75: Failure

@trustin
Copy link
Member Author

trustin commented Nov 22, 2013

(Re: deprecation) I'll remove them. We should keep their adapters though, right?

@normanmaurer
Copy link
Member

Yeah ... I think most users will use adapters anyway so most should not be affected hopefully.

So after this and the handler name change please merge in

Am 22.11.2013 um 17:23 schrieb Trustin Lee notifications@github.com:

(Re: deprecation) I'll remove them. We should keep their adapters though, right?


Reply to this email directly or view it on GitHub.

@ghost
Copy link

ghost commented Nov 22, 2013

Build result for #1999 at 376c5dc: Failure

@ghost
Copy link

ghost commented Nov 22, 2013

Build result for #1999 at b64ac31: Success

@ghost
Copy link

ghost commented Nov 22, 2013

Build result for #1999 at 4ff9413: Success

@normanmaurer
Copy link
Member

@trustin just did some benchmarks and it seems like it improves performance :) So once deprecation stuff is fixed please squash and merge in.

@ghost
Copy link

ghost commented Nov 25, 2013

Build result for #1999 at 7a41206: Success

@normanmaurer
Copy link
Member

@jpinner @wgallagher could you please review so we can move ahead ?

- Move all methods in ChannelInboundHandler and ChannelOutboundHandler up to ChannelHandler
- Remove ChannelInboundHandler and ChannelOutboundHandler
- Deprecate ChannelInboundHandlerAdapter, ChannelOutboundHandlerAdapter, and ChannelDuplexHandler
- Replace CombinedChannelDuplexHandler with ChannelHandlerAppender
  because it's not possible to combine two handlers into one easily now
- Introduce 'Skip' annotation to pass events through efficiently
- Remove all references to the deprecated types and update Javadoc
@ghost
Copy link

ghost commented Nov 27, 2013

Build result for #1999 at 31116de: Success

@trustin trustin closed this Nov 27, 2013
@trustin trustin deleted the one_handler branch November 27, 2013 08:32
@trustin
Copy link
Member Author

trustin commented Nov 27, 2013

Merged via 110745b.

@ghost ghost assigned trustin Nov 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants