Class RouteSegmentedConnPool<R,​C extends ModalCloseable>

    • Field Detail

      • timeToLive

        private final TimeValue timeToLive
      • defaultMaxPerRoute

        private final java.util.concurrent.atomic.AtomicInteger defaultMaxPerRoute
      • maxPerRoute

        private final java.util.concurrent.ConcurrentHashMap<R,​java.lang.Integer> maxPerRoute
      • totalAllocated

        private final java.util.concurrent.atomic.AtomicInteger totalAllocated
      • maxTotal

        private final java.util.concurrent.atomic.AtomicInteger maxTotal
      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
      • timeouts

        private final java.util.concurrent.ScheduledExecutorService timeouts
      • disposer

        private final java.util.concurrent.ThreadPoolExecutor disposer
        Dedicated executor for asynchronous, best-effort disposal. Bounded queue; on saturation we fall back to IMMEDIATE close on the caller thread.
      • pendingQueue

        private final java.util.concurrent.ConcurrentLinkedQueue<R> pendingQueue
      • draining

        private final java.util.concurrent.atomic.AtomicBoolean draining
      • pendingRouteCount

        private final java.util.concurrent.atomic.AtomicInteger pendingRouteCount
    • Method Detail

      • lease

        public java.util.concurrent.Future<PoolEntry<R,​C>> lease​(R route,
                                                                       java.lang.Object state,
                                                                       Timeout requestTimeout,
                                                                       FutureCallback<PoolEntry<R,​C>> callback)
        Description copied from interface: ConnPool
        Attempts to lease a connection for the given route and with the given state from the pool.

        Please note the connection request can get automatically cancelled by the pool in case of a request timeout.

        Specified by:
        lease in interface ConnPool<R,​C extends ModalCloseable>
        Parameters:
        route - route of the connection.
        state - arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.
        requestTimeout - request timeout. In case of a timeout the request can get automatically cancelled by the pool.
        callback - operation completion callback.
        Returns:
        future for a leased pool entry.
      • release

        public void release​(PoolEntry<R,​C> entry,
                            boolean reusable)
        Description copied from interface: ConnPool
        Releases the pool entry back to the pool.
        Specified by:
        release in interface ConnPool<R,​C extends ModalCloseable>
        Parameters:
        entry - pool entry leased from the pool
        reusable - flag indicating whether or not the released connection is in a consistent state and is safe for further use.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • close

        public void close​(CloseMode closeMode)
        Description copied from interface: ModalCloseable
        Closes this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.
        Specified by:
        close in interface ModalCloseable
        Parameters:
        closeMode - How to close the receiver.
      • ensureOpen

        private void ensureOpen()
      • isPastTtl

        private boolean isPastTtl​(PoolEntry<R,​C> p)
      • compatible

        private boolean compatible​(java.lang.Object needed,
                                   java.lang.Object have)
      • triggerDrainIfMany

        private void triggerDrainIfMany()
      • serveRoundRobin

        private void serveRoundRobin​(int budget)
      • discardEntry

        private void discardEntry​(PoolEntry<R,​C> p,
                                  CloseMode preferred)
        Dispose a pool entry's connection asynchronously if possible; under pressure fall back to IMMEDIATE on caller.