-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8350279: HttpClient: Add a new HttpResponse method to identify connections #24154
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back vyazici! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
Webrevs
|
test/jdk/java/net/httpclient/HttpResponseConnectionLabelTest.java
Outdated
Show resolved
Hide resolved
test/jdk/java/net/httpclient/HttpResponseConnectionLabelTest.java
Outdated
Show resolved
Hide resolved
src/java.net.http/share/classes/jdk/internal/net/http/HttpResponseImpl.java
Outdated
Show resolved
Hide resolved
src/java.net.http/share/classes/jdk/internal/net/http/HttpResponseImpl.java
Outdated
Show resolved
Hide resolved
src/java.net.http/share/classes/jdk/internal/net/http/HttpResponseImpl.java
Outdated
Show resolved
Hide resolved
src/java.net.http/share/classes/jdk/internal/net/http/HttpResponseImpl.java
Outdated
Show resolved
Hide resolved
/csr required |
This new API returns an
|
…nectionLabel` Co-authored-by: Daniel Fuchs <67001856+dfuch@users.noreply.github.com>
…nectionLabelTest`
/csr needed |
@vy has indicated that a compatibility and specification (CSR) request is needed for this pull request. @vy please create a CSR request for issue JDK-8350279 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
No. If empty is returned you can make no assumptions. In practice this should never be null with our impl (except possibly in whitebox tests)
Yes. |
Should we specify this, like "The JDK built-in implementation of the {@code HttpClient} always assign a label to connections it create"? |
Good question - that would be an |
* {@return a label identifying the connection to facilitate | ||
* {@link HttpResponse#connectionLabel() HttpResponse::connectionLabel}} | ||
*/ | ||
public String label() { |
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.
Perhaps make this method final
?
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.
Maybe not. We could want to extend it to give an indication that the connection is TCP or TLS - or Quic in the future...
@@ -44,6 +44,7 @@ | |||
class HttpResponseImpl<T> implements HttpResponse<T>, RawChannel.Provider { |
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.
The copyright year on this file will need an update.
* connection. For instance, an {@link AsyncSSLConnection} and the | ||
* {@link PlainHttpConnection} it wraps will share the same label. As a | ||
* result, compared to {@link #id}, this label does not give a total order | ||
* among instances. |
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.
Hello Volkan, I think we shouldn't talk about any kind of ordering here. I see that the id
field has been updated with a comment stating that it provides ordering among instances. Even there, I don't think that comment about ordering is needed. So far we haven't used the id
to mean anything other than a logical identifier and these values have played no role in ordering of connections at any place. So adding the comments about ordering, I think, makes it confusing.
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.
The only use of HttpConnection.id
is for ordering - so that connections can be placed in a ConcurrentSkipListSet. So maybe here we should not speak of ordering (remove the last sentence in that paragraph) - but I think it helps to keep it for id
.
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.
The only use of HttpConnection.id is for ordering - so that connections can be placed in a ConcurrentSkipListSet.
I wasn't aware of that. Now that you mentioned it, I looked up the code which uses the Set to store these connections. And from what I can see, the order is only used during the closing of a HttpClient, to close these opened connections in that specific order. Did I miss any other usages of the order?
In any case, now that you corrected me about the usage of the id
order, I agree that having the comment on the id
field is fine and only remove it from the paragraph here.
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.
When we close a connection, we take it out of the set. So it's not about ordering the connection but about quickly finding the connection in that set.
* among instances. | ||
* </p> | ||
*/ | ||
final String label; |
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.
I think this should be private
.
@@ -76,17 +78,48 @@ abstract class HttpConnection implements Closeable { | |||
public static final Comparator<HttpConnection> COMPARE_BY_ID | |||
= Comparator.comparing(HttpConnection::id); | |||
|
|||
private static final AtomicLong LABEL_COUNTER = new AtomicLong(); |
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.
In the API documentation on HttpResponse.connectionLabel()
we talk about the connection label being unique within a HttpClient
scope. i.e. two different HttpClient
instances could have the same connectionLabel for a connection. I think that's the right scoping.
So given that, having a static
field on a HttpConnection
which keeps track of a connection label, may not be the right place to keep track of that state. In this proposed form, no two connections in two different HttpClient instances will ever have the same connectionLabel. I think this counter should probably be present on the HttpClientImpl
as an instance field.
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.
I believe that's OK. We could go either way - but I'd rather keep the label unique regardless of the client because otherwise we would also need to include the client id in the debug traces (ATM we only have the label). If it's unique in the scope of the VM it's a fortiori unique in the scope of the client instance.
Adds
HttpResponse::connectionLabel
method that provides an identifier for the connection.Implementation note: The feature is facilitated by
HttpConnection::label
, which should not be confused withHttpConnection::id
. This distinction is explained in the JavaDoc of both properties.Progress
Issues
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24154/head:pull/24154
$ git checkout pull/24154
Update a local copy of the PR:
$ git checkout pull/24154
$ git pull https://git.openjdk.org/jdk.git pull/24154/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24154
View PR using the GUI difftool:
$ git pr show -t 24154
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24154.diff
Using Webrev
Link to Webrev Comment