Skip to content

Conversation

stepancheg
Copy link
Contributor

  • 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.

private Semaphore getFreeConnectionsForHost(Object partitionKey) {
return freeChannelsPerHost.computeIfAbsent(partitionKey, pk -> new Semaphore(config.getMaxConnectionsPerHost()));
private NonBlockingSemaphoreLike getFreeConnectionsForHost(Object partitionKey) {
if (maxConnectionsPerHostEnabled) {
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

NoopNonBlockingSemaphore?

Copy link
Contributor Author

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.
2017-03-28_2023

* @author Stepan Koltsov
*/
enum NonBlockingSemaphoreInfinite implements NonBlockingSemaphoreLike {
I;
Copy link
Contributor

Choose a reason for hiding this comment

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

INSTANCE?

@slandelle
Copy link
Contributor

@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.
@stepancheg
Copy link
Contributor Author

Addressed all the issues except name of semaphore class, see comments above.

@slandelle
Copy link
Contributor

Great job, thanks!

@slandelle slandelle merged commit 29d0667 into AsyncHttpClient:master Mar 28, 2017
@slandelle slandelle added this to the 2.0.32 milestone Mar 28, 2017
slandelle pushed a commit that referenced this pull request Mar 28, 2017
* 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.
slandelle pushed a commit that referenced this pull request Mar 28, 2017
* 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.
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.

2 participants