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

Move exceptionCaught(..) and userEventTriggered(..) to ChannelStateHandler #1107

Closed
normanmaurer opened this issue Feb 28, 2013 · 27 comments
Closed
Assignees
Milestone

Comments

@normanmaurer
Copy link
Member

While I was working on the Netty in Action book I notice something I would like to change in our current ChannelHandler hierarchy. So here we go.

I think we should exceptionCaught(..) and userEventTriggered(..) to ChannelStateHandler (currently in ChannelHandler).

The main reasons are:

  1. These two callbacks will be called as result of ChannelInboundInvoker.* methods. All others callbacks that are called because of it are already part of ChannelStateHandler. So it is more consistent
  2. exceptionCaught(..) should never be called because of an outbound operation. For these the ChannelPromise must be failed if an error happens. So it is missleading to have it part of ChannelHandler as ChannelOperationHandler and ChannelOutboundHandler extend it and so expose it.
@ghost ghost assigned normanmaurer Feb 28, 2013
@normanmaurer
Copy link
Member Author

@trustin wdyt ?

@jpinner
Copy link

jpinner commented Feb 28, 2013

w.r.t to moving those from "base" ChannelHandler to the "upstream" ChannelHandler, that sounds find by me since they are "upstream" messages - sry about the netty3 syntax, not going to try to context swap this early in the morning :)

Not sure I agree with the second statement you made though. exceptionCaught(..) can be called because of an outband operation and some Netty handlers rely on this -- WriteTimeoutHandler for example

@trustin
Copy link
Member

trustin commented Feb 28, 2013

This leads myself to an interesting idea: how about just merging ChannelStateHandler and ChannelOperationHandler into ChannelHandler? That will make our handler type hierarchy much simpler and also reduce the number of adapter classes.

I wonder how much this will affect the performance. It will make the call stack deeper but it will make pipeline implementation simpler.

@normanmaurer
Copy link
Member Author

Then we could also merge ChannelHandler in... Maybe a good idea!

Sent from my iPhone. Excuse any typos....

Am 28.02.2013 um 18:49 schrieb Trustin Lee notifications@github.com:

This leads myself to an interesting idea: how about just merging ChannelStateHandler and ChannelOperationHandler into ChannelHandler? That will make our handler type hierarchy much simpler and also reduce the number of adapter classes.

I wonder how much this will affect the performance. It will make the call stack deeper but it will make pipeline implementation simpler.


Reply to this email directly or view it on GitHub.

@normanmaurer
Copy link
Member Author

@trustin just noticed this is exactly what you said... So deal ?

@trustin
Copy link
Member

trustin commented Feb 28, 2013

Deal. Another breakage :-)

@normanmaurer
Copy link
Member Author

yeah... I will take care, so we both are guilty ;)

@trustin
Copy link
Member

trustin commented Feb 28, 2013

Just make sure there's no perf regression. :-)

@normanmaurer
Copy link
Member Author

Yeah will test... If it really makes a big difference we can just do what I proposed before

Sent from my iPhone. Excuse any typos....

Am 28.02.2013 um 19:52 schrieb Trustin Lee notifications@github.com:

Just make sure there's no perf regression. :-)


Reply to this email directly or view it on GitHub.

@normanmaurer
Copy link
Member Author

@trustin one think I just notice is that it will break our ChannelDuplexHandler as it is not easy to combine two handlers anymore.. maybe we should just go with my first idea.. WDYT ?

@normanmaurer
Copy link
Member Author

Sorry I was talking about CombinedChannelDuplexHandler

@normanmaurer
Copy link
Member Author

@trustin so any preference ? I would like to just move the two methods...

@jpinner
Copy link

jpinner commented Mar 1, 2013

-1 to merging them

it will break all of the combined encoder/decoder codecs

@normanmaurer
Copy link
Member Author

@jpinner yeah that is why I just want to move the two methods. As otherwise it impossible to combine.

@trustin
Copy link
Member

trustin commented Mar 4, 2013

Agreed. #1111 looks fine to me. Let's merge!

@normanmaurer
Copy link
Member Author

merged in.. thanks!

@normanmaurer
Copy link
Member Author

I think we should re-open this and think again about it. After my work on out-of-order events in the pipeline I think again we should move the exceptionCaught(...) method to ChannelStateHandler. This will also make the contract clear in which direction the pipeline is processed. If someone wants to react on exceptionCaught and its own impl is only a ChannelOperationHandler he just need to add another handler in or make his handler also implement ChannelStateHandler.

@jpinner @trustin WDYT ?

@normanmaurer
Copy link
Member Author

So for example the ReadTimeoutHandler would just extend ChannelDuplexHandler.

@trustin
Copy link
Member

trustin commented Apr 20, 2013

I see no problem with the current contract? Also, if we move it to ChannelStateHandler, an operation handler that raised an exception mistakenly can never be notified.

Norman Maurer notifications@github.com wrote:

I think we should re-open this and think again about it. After my work
on out-of-order events in the pipeline I think again we should move the
exceptionCaught(...) method to ChannelStateHandler. This will also make
the contract clear in which direction the pipeline is processed. If
someone wants to react on exceptionCaught and its own impl is only a
ChannelOperationHandler he just need to add another handler in or make
his handler also implement ChannelStateHandler.

@jpinner @trustin WDYT ?


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

@ghost
Copy link

ghost commented Apr 20, 2013

s/notified/notified to the operation handler which raised the exception/

Trustin Lee notifications@github.com wrote:

I see no problem with the current contract? Also, if we move it to
ChannelStateHandler, an operation handler that raised an exception
mistakenly can never be notified.

Norman Maurer notifications@github.com wrote:

I think we should re-open this and think again about it. After my work
on out-of-order events in the pipeline I think again we should move
the
exceptionCaught(...) method to ChannelStateHandler. This will also
make
the contract clear in which direction the pipeline is processed. If
someone wants to react on exceptionCaught and its own impl is only a
ChannelOperationHandler he just need to add another handler in or make
his handler also implement ChannelStateHandler.

@jpinner @trustin WDYT ?


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

@normanmaurer
Copy link
Member Author

I would even say we should remove throw Exception from all methods for a operation handler as it should notify the promise on failure, no?

Am 20.04.2013 um 05:48 schrieb Trustin Lee notifications@github.com:

I see no problem with the current contract? Also, if we move it to ChannelStateHandler, an operation handler that raised an exception mistakenly can never be notified.

Norman Maurer notifications@github.com wrote:

I think we should re-open this and think again about it. After my work
on out-of-order events in the pipeline I think again we should move the
exceptionCaught(...) method to ChannelStateHandler. This will also make
the contract clear in which direction the pipeline is processed. If
someone wants to react on exceptionCaught and its own impl is only a
ChannelOperationHandler he just need to add another handler in or make
his handler also implement ChannelStateHandler.

@jpinner @trustin WDYT ?


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

Reply to this email directly or view it on GitHub.

@trustin
Copy link
Member

trustin commented Apr 20, 2013

That's an interesting idea. I don't think we need to remove 'throws Exception' but just need to catch it in DefaultChannelHandlerContext. However, we can't notify the caught exception if the handler already forwarded the promise to the next handler or the promise has been fulfilled.

Norman Maurer notifications@github.com wrote:

I would even say we should remove throw Exception from all methods for
a operation handler as it should notify the promise on failure, no?

Am 20.04.2013 um 05:48 schrieb Trustin Lee notifications@github.com:

I see no problem with the current contract? Also, if we move it to
ChannelStateHandler, an operation handler that raised an exception
mistakenly can never be notified.

Norman Maurer notifications@github.com wrote:

I think we should re-open this and think again about it. After my
work
on out-of-order events in the pipeline I think again we should move
the
exceptionCaught(...) method to ChannelStateHandler. This will also
make
the contract clear in which direction the pipeline is processed. If
someone wants to react on exceptionCaught and its own impl is only a
ChannelOperationHandler he just need to add another handler in or
make
his handler also implement ChannelStateHandler.

@jpinner @trustin WDYT ?


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

@normanmaurer
Copy link
Member Author

That's true but it just doesn't sound right to allow throw an exception if a promise is passed in. It makes the contract more clear, at least for me ;)

Am 20.04.2013 um 09:31 schrieb Trustin Lee notifications@github.com:

That's an interesting idea. I don't think we need to remove 'throws Exception' but just need to catch it in DefaultChannelHandlerContext. However, we can't notify the caught exception if the handler already forwarded the promise to the next handler or the promise has been fulfilled.

Norman Maurer notifications@github.com wrote:

I would even say we should remove throw Exception from all methods for
a operation handler as it should notify the promise on failure, no?

Am 20.04.2013 um 05:48 schrieb Trustin Lee notifications@github.com:

I see no problem with the current contract? Also, if we move it to
ChannelStateHandler, an operation handler that raised an exception
mistakenly can never be notified.

Norman Maurer notifications@github.com wrote:

I think we should re-open this and think again about it. After my
work
on out-of-order events in the pipeline I think again we should move
the
exceptionCaught(...) method to ChannelStateHandler. This will also
make
the contract clear in which direction the pipeline is processed. If
someone wants to react on exceptionCaught and its own impl is only a
ChannelOperationHandler he just need to add another handler in or
make
his handler also implement ChannelStateHandler.

@jpinner @trustin WDYT ?


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

Reply to this email directly or view it on GitHub.

@normanmaurer
Copy link
Member Author

Also if already notify we can just log the exception and close the channel. As this is most likely a user error / bug.

Am 20.04.2013 um 09:31 schrieb Trustin Lee notifications@github.com:

That's an interesting idea. I don't think we need to remove 'throws Exception' but just need to catch it in DefaultChannelHandlerContext. However, we can't notify the caught exception if the handler already forwarded the promise to the next handler or the promise has been fulfilled.

Norman Maurer notifications@github.com wrote:

I would even say we should remove throw Exception from all methods for
a operation handler as it should notify the promise on failure, no?

Am 20.04.2013 um 05:48 schrieb Trustin Lee notifications@github.com:

I see no problem with the current contract? Also, if we move it to
ChannelStateHandler, an operation handler that raised an exception
mistakenly can never be notified.

Norman Maurer notifications@github.com wrote:

I think we should re-open this and think again about it. After my
work
on out-of-order events in the pipeline I think again we should move
the
exceptionCaught(...) method to ChannelStateHandler. This will also
make
the contract clear in which direction the pipeline is processed. If
someone wants to react on exceptionCaught and its own impl is only a
ChannelOperationHandler he just need to add another handler in or
make
his handler also implement ChannelStateHandler.

@jpinner @trustin WDYT ?


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub:
#1107 (comment)

sent from a mobile device
https://twitter.com/trustin
https://twitter.com/trustin_ko
https://twitter.com/netty_project

Reply to this email directly or view it on GitHub.

@normanmaurer
Copy link
Member Author

@trustin I think once we know if we should change this or not we can just cut CR2 as I don't think the pipeline lifecycle stuff will need any api changes to get fixed. CR2 is long overdue...

I would change it ;)

@trustin
Copy link
Member

trustin commented Apr 23, 2013

As we agreed to disagree, I'm going to close this for now. ;-)

@trustin trustin closed this as completed Apr 23, 2013
@He-Pin
Copy link
Contributor

He-Pin commented Apr 23, 2013

@normanmaurer I do think the overdue doesn't matter but the quality matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants