-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add ClientConnectionListener listener #12421
base: jetty-12.0.x
Are you sure you want to change the base?
Conversation
Signed-off-by: Oleksandr Krutko <[email protected]>
@arsenalzp Would it be OK if we implemented this in jetty-12.1.0 rather than 12.0.x? We are trying to feature freeze 12.0 |
This approach is OK for me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arsenalzp good start.
Please review my comments, but I really need you to add test cases.
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
Of course it is good to have test cases, however as I said it is the draft, just to show the framework of solution. |
Signed-off-by: Oleksandr Krutko <[email protected]>
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
I'm thinking about the place of What do you think? |
@arsenalzp put the test class in the |
@arsenalzp please also fix the formatting, see here why the build fails: |
Yeah, issue has been fixed already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arsenalzp another thing.
Instead of calling getBeans(ClientConnector.ConnectListener.class)
every time, which is an expensive operation, please override add/removeEventListener
, and store the ConnectListener
in a local CopyOnWriteArrayList
field, so the notification is faster.
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
Hello,
|
@arsenalzp in the base class you have a field for I am proposing that you do similarly in |
Signed-off-by: Oleksandr Krutko <[email protected]>
Signed-off-by: Oleksandr Krutko <[email protected]>
It is clear for me now, thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arsenalzp another good step, please review my comments.
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ClientConnector.java
Outdated
Show resolved
Hide resolved
boolean blocking = isConnectBlocking() && address instanceof InetSocketAddress; | ||
if (LOG.isDebugEnabled()) | ||
LOG.debug("Connecting {} to {}", blocking ? "blocking" : "non-blocking", address); | ||
if (blocking) | ||
{ | ||
listeners.forEach(listener -> listener.onConnectBegin(socketChannel, socketAddress)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These calls should be wrapped, since we do not want an exception thrown from onConnectBegin()
to stop the connection.
Make a method, say connectBegin()
, use a for
loop instead of forEach()
, and wrap listener.onConnectBegin()
into try/catch(Throwable)
.
And same for the other events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason of this solution?
ConnectListener
methods don't throw an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConnectListener
implementations are user code, and it can throw any RuntimeException
, but we do not want ClientConnector
internal working to be affected by that if it happens.
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Oleksandr Krutko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arsenalzp looks good, two things:
- wrap the calls to
ConnectListener
methods intotry/catch(Throwable)
. - Write tests.
Thanks!
{ | ||
if (listener instanceof ConnectListener connectListener) | ||
return listeners.add(connectListener); | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you need to call super
here.
{ | ||
if (listener instanceof ConnectListener connectListener) | ||
return listeners.remove(connectListener); | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you need to call super
here.
*/ | ||
protected void connectSuccess(SelectableChannel channel) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this newline.
@@ -753,4 +768,29 @@ public ChannelWithAddress newChannelWithAddress(ClientConnector clientConnector, | |||
}; | |||
} | |||
} | |||
|
|||
public interface ConnectListener extends EventListener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add javadocs to class and methods.
Here is the draft of changes proposed to solve #9529
Let's discuss it in the issue thread as the implementation was not hardened yet.