-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Simplify semaphore logic in ChannelManager #1372
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
Conversation
private Semaphore getFreeConnectionsForHost(Object partitionKey) { | ||
return freeChannelsPerHost.computeIfAbsent(partitionKey, pk -> new Semaphore(config.getMaxConnectionsPerHost())); | ||
private NonBlockingSemaphoreLike getFreeConnectionsForHost(Object partitionKey) { | ||
if (maxConnectionsPerHostEnabled) { |
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.
ternary operator
@@ -139,18 +138,23 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) { | |||
maxTotalConnectionsEnabled = config.getMaxConnections() > 0; | |||
maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0; | |||
|
|||
if (maxTotalConnectionsEnabled) { |
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.
ternary operator
@@ -0,0 +1,35 @@ | |||
package org.asynchttpclient.netty.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.
Please add package header, granting copyright to "The AsyncHttpClient" project, just like in ChannelManager
but with inception year 2017.
@@ -0,0 +1,21 @@ | |||
package org.asynchttpclient.netty.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.
Please add missing file header
@@ -0,0 +1,12 @@ | |||
package org.asynchttpclient.netty.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.
Please add missing file header
@@ -0,0 +1,63 @@ | |||
package org.asynchttpclient.netty.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.
Please add missing file header
* | ||
* @author Stepan Koltsov | ||
*/ | ||
enum NonBlockingSemaphoreInfinite implements NonBlockingSemaphoreLike { |
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.
NoopNonBlockingSemaphore
?
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-op does not make it clear that tryAcquire
returns true. Infinite
make it look like a semaphore with infinite number of permits, so tryAcquire
always returns true.
I put Infinite
part at the end of the class name so classes were together in the file list in the IDE.
So I think names are good, but I can change both name and placement if you still think it is better.
* @author Stepan Koltsov | ||
*/ | ||
enum NonBlockingSemaphoreInfinite implements NonBlockingSemaphoreLike { | ||
I; |
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.
INSTANCE
?
@stepancheg Thanks! Could you please address comments? |
* avoid using `java.util.concurrent.Semaphore` which is blocking, and its blocking part is not used, which is confusing. * Use `NonBlockingSemaphoreInfinite` to avoid nulls and ifs when connection count is not limited.
Addressed all the issues except name of semaphore class, see comments above. |
Great job, thanks! |
* avoid using `java.util.concurrent.Semaphore` which is blocking, and its blocking part is not used, which is confusing. * Use `NonBlockingSemaphoreInfinite` to avoid nulls and ifs when connection count is not limited.
* avoid using `java.util.concurrent.Semaphore` which is blocking, and its blocking part is not used, which is confusing. * Use `NonBlockingSemaphoreInfinite` to avoid nulls and ifs when connection count is not limited.
java.util.concurrent.Semaphore
which is blocking,and its blocking part is not used, which is confusing.
NonBlockingSemaphoreInfinite
to avoid nulls and ifswhen connection count is not limited.