Class PerHostConnectionSemaphore

    • Field Detail

      • maxConnectionsPerHost

        protected final int maxConnectionsPerHost
      • tooManyConnectionsPerHost

        protected final IOException tooManyConnectionsPerHost
      • acquireTimeout

        protected final int acquireTimeout
    • Method Detail

      • acquireChannelLock

        public void acquireChannelLock​(Object partitionKey,
                                       boolean nonBlocking)
                                throws IOException
        Description copied from interface: ConnectionSemaphore
        Acquires a connection permit for partitionKey, optionally without blocking.

        When nonBlocking is true a 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. When false this behaves exactly like ConnectionSemaphore.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 honour nonBlocking.

        Specified by:
        acquireChannelLock in interface ConnectionSemaphore
        Parameters:
        partitionKey - the per-host partition key the permit is scoped to
        nonBlocking - true to fail fast instead of waiting for a permit
        Throws:
        IOException - if no permit could be acquired
      • getFreeConnectionsForHost

        @Deprecated
        protected Semaphore getFreeConnectionsForHost​(Object partitionKey)
        Deprecated.
        does not participate in the reference-counted reservation bookkeeping that acquireChannelLock(Object, boolean)/releaseChannelLock(Object) rely on to prune idle host entries, so a permit acquired through the returned Semaphore should be released through the same instance rather than through releaseChannelLock(Object). Delegates to reserveFreeConnectionsForHost(Object) so the returned instance is always the map's current TrackedSemaphore for this key, kept only for binary compatibility.