Class PerHostConnectionSemaphore
- java.lang.Object
-
- org.asynchttpclient.netty.channel.PerHostConnectionSemaphore
-
- All Implemented Interfaces:
ConnectionSemaphore
- Direct Known Subclasses:
CombinedConnectionSemaphore
public class PerHostConnectionSemaphore extends Object implements ConnectionSemaphore
Max per-host connections limiter.
-
-
Field Summary
Fields Modifier and Type Field Description protected intacquireTimeoutprotected ConcurrentHashMap<Object,Semaphore>freeChannelsPerHostprotected intmaxConnectionsPerHostprotected IOExceptiontooManyConnectionsPerHost
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidacquireChannelLock(Object partitionKey)voidacquireChannelLock(Object partitionKey, boolean nonBlocking)Acquires a connection permit forpartitionKey, optionally without blocking.protected SemaphoregetFreeConnectionsForHost(Object partitionKey)Deprecated.does not participate in the reference-counted reservation bookkeeping thatacquireChannelLock(Object, boolean)/releaseChannelLock(Object)rely on to prune idle host entries, so a permit acquired through the returnedSemaphoreshould be released through the same instance rather than throughreleaseChannelLock(Object).voidreleaseChannelLock(Object partitionKey)
-
-
-
Field Detail
-
freeChannelsPerHost
protected final ConcurrentHashMap<Object,Semaphore> freeChannelsPerHost
-
maxConnectionsPerHost
protected final int maxConnectionsPerHost
-
tooManyConnectionsPerHost
protected final IOException tooManyConnectionsPerHost
-
acquireTimeout
protected final int acquireTimeout
-
-
Method Detail
-
acquireChannelLock
public void acquireChannelLock(Object partitionKey) throws IOException
- Specified by:
acquireChannelLockin interfaceConnectionSemaphore- Throws:
IOException
-
acquireChannelLock
public void acquireChannelLock(Object partitionKey, boolean nonBlocking) throws IOException
Description copied from interface:ConnectionSemaphoreAcquires a connection permit forpartitionKey, optionally without blocking.When
nonBlockingistruea permit must be taken without waiting — the too-many-connections exception is thrown immediately if none is free. This is used when the caller runs on a Netty event-loop thread (a redirect / 401 / 407 / retry replay re-enters the send path on the event loop), where waiting for the configured acquire timeout would freeze the loop and stall every other connection it serves. Whenfalsethis behaves exactly likeConnectionSemaphore.acquireChannelLock(Object).The default implementation ignores the hint and delegates to the blocking
ConnectionSemaphore.acquireChannelLock(Object), preserving the behaviour of custom implementations; the built-in limiters override it to honournonBlocking.- Specified by:
acquireChannelLockin interfaceConnectionSemaphore- Parameters:
partitionKey- the per-host partition key the permit is scoped tononBlocking-trueto fail fast instead of waiting for a permit- Throws:
IOException- if no permit could be acquired
-
releaseChannelLock
public void releaseChannelLock(Object partitionKey)
- Specified by:
releaseChannelLockin interfaceConnectionSemaphore
-
getFreeConnectionsForHost
@Deprecated protected Semaphore getFreeConnectionsForHost(Object partitionKey)
Deprecated.does not participate in the reference-counted reservation bookkeeping thatacquireChannelLock(Object, boolean)/releaseChannelLock(Object)rely on to prune idle host entries, so a permit acquired through the returnedSemaphoreshould be released through the same instance rather than throughreleaseChannelLock(Object). Delegates toreserveFreeConnectionsForHost(Object)so the returned instance is always the map's currentTrackedSemaphorefor this key, kept only for binary compatibility.
-
-