Class AbstractConnectionPool

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ConnectionPool, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.util.thread.Sweeper.Sweepable
    Direct Known Subclasses:
    DuplexConnectionPool, MultiplexConnectionPool

    @ManagedObject
    public abstract class AbstractConnectionPool
    extends org.eclipse.jetty.util.component.ContainerLifeCycle
    implements ConnectionPool, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.thread.Sweeper.Sweepable
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
      • Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

        org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
      • Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

        org.eclipse.jetty.util.component.Dumpable.DumpableContainer
      • Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

        org.eclipse.jetty.util.component.LifeCycle.Listener
    • Field Summary

      • Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
      • Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

        KEY
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Connection acquire()
      Returns an idle connection, if available, or schedules the opening of a new connection and returns null.
      protected Connection acquire​(boolean create)
      Returns an idle connection, if available; if an idle connection is not available, and the given create parameter is true or isMaximizeConnections() is true, then attempts to open a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise it attempts to open a new connection, if the number of queued requests is greater than the number of pending connections; if no connection is available even after the attempts to open, return null.
      protected void acquired​(Connection connection)  
      protected Connection activate()  
      void close()
      Closes this ConnectionPool.
      protected boolean deactivate​(Connection connection)  
      protected void doStop()  
      void dump​(java.lang.Appendable out, java.lang.String indent)  
      int getActiveConnectionCount()  
      java.util.Collection<Connection> getActiveConnections()
      Deprecated.
      Relying on this method indicates a reliance on the implementation details.
      int getConnectionCount()  
      int getIdleConnectionCount()  
      java.util.Queue<Connection> getIdleConnections()
      Deprecated.
      Relying on this method indicates a reliance on the implementation details.
      int getMaxConnectionCount()  
      long getMaxDuration()
      Get the max usage duration in milliseconds of the pool's connections.
      protected int getMaxMultiplex()  
      protected int getMaxUsageCount()  
      int getPendingConnectionCount()  
      int getPendingCount()
      Deprecated.
      protected boolean idle​(Connection connection, boolean close)  
      boolean isActive​(Connection connection)  
      boolean isClosed()  
      boolean isEmpty()  
      boolean isMaximizeConnections()  
      protected void onCreated​(Connection connection)  
      java.util.concurrent.CompletableFuture<java.lang.Void> preCreateConnections​(int connectionCount)
      Optionally pre-create up to connectionCount connections so they are immediately ready for use.
      protected void proceed()  
      boolean release​(Connection connection)
      Returns the given connection, previously obtained via ConnectionPool.acquire(), back to this ConnectionPool.
      protected void released​(Connection connection)  
      boolean remove​(Connection connection)
      Removes the given connection from this ConnectionPool.
      protected boolean remove​(Connection connection, boolean force)
      Deprecated.
      protected void removed​(Connection connection)  
      void setMaxDuration​(long maxDurationInMs)  
      void setMaximizeConnections​(boolean maximizeConnections)
      Sets whether the number of connections should be maximized.
      protected void setMaxMultiplex​(int maxMultiplex)  
      protected void setMaxUsageCount​(int maxUsageCount)  
      boolean sweep()  
      java.lang.String toString()  
      protected void tryCreate​(boolean create)
      Tries to create a new connection.
      • Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

        addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
      • Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

        dump, dumpSelf
      • Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

        isDumpable
    • Constructor Detail

      • AbstractConnectionPool

        protected AbstractConnectionPool​(HttpDestination destination,
                                         int maxConnections,
                                         boolean cache,
                                         org.eclipse.jetty.util.Callback requester)
      • AbstractConnectionPool

        protected AbstractConnectionPool​(HttpDestination destination,
                                         org.eclipse.jetty.util.Pool.StrategyType strategy,
                                         int maxConnections,
                                         boolean cache,
                                         org.eclipse.jetty.util.Callback requester)
      • AbstractConnectionPool

        protected AbstractConnectionPool​(HttpDestination destination,
                                         org.eclipse.jetty.util.Pool<Connection> pool,
                                         org.eclipse.jetty.util.Callback requester)
    • Method Detail

      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Overrides:
        doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        java.lang.Exception
      • preCreateConnections

        public java.util.concurrent.CompletableFuture<java.lang.Void> preCreateConnections​(int connectionCount)
        Description copied from interface: ConnectionPool
        Optionally pre-create up to connectionCount connections so they are immediately ready for use.
        Specified by:
        preCreateConnections in interface ConnectionPool
        Parameters:
        connectionCount - the number of connections to pre-start.
      • getMaxDuration

        @ManagedAttribute("The maximum duration in milliseconds a connection can be used for before it gets closed")
        public long getMaxDuration()

        Get the max usage duration in milliseconds of the pool's connections. Values 0 and negative mean that there is no limit.

        This only guarantees that a connection cannot be acquired after the configured duration elapses, so that is only enforced when acquire() is called. If a pool stays completely idle for a duration longer than the value returned by this method, the max duration will not be enforced. It's up to the idle timeout mechanism (see HttpClient.getIdleTimeout()) to handle closing idle connections.

      • setMaxDuration

        public void setMaxDuration​(long maxDurationInMs)
      • getMaxMultiplex

        protected int getMaxMultiplex()
      • setMaxMultiplex

        protected void setMaxMultiplex​(int maxMultiplex)
      • getMaxUsageCount

        protected int getMaxUsageCount()
      • setMaxUsageCount

        protected void setMaxUsageCount​(int maxUsageCount)
      • getActiveConnectionCount

        @ManagedAttribute(value="The number of active connections",
                          readonly=true)
        public int getActiveConnectionCount()
      • getIdleConnectionCount

        @ManagedAttribute(value="The number of idle connections",
                          readonly=true)
        public int getIdleConnectionCount()
      • getMaxConnectionCount

        @ManagedAttribute(value="The max number of connections",
                          readonly=true)
        public int getMaxConnectionCount()
      • getConnectionCount

        @ManagedAttribute(value="The number of connections",
                          readonly=true)
        public int getConnectionCount()
      • getPendingCount

        @ManagedAttribute(value="The number of pending connections",
                          readonly=true)
        @Deprecated
        public int getPendingCount()
        Deprecated.
        Returns:
        the number of pending connections
      • getPendingConnectionCount

        @ManagedAttribute(value="The number of pending connections",
                          readonly=true)
        public int getPendingConnectionCount()
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface ConnectionPool
        Returns:
        whether this ConnectionPool has no open connections
      • isClosed

        @ManagedAttribute("Whether this pool is closed")
        public boolean isClosed()
        Specified by:
        isClosed in interface ConnectionPool
        Returns:
        whether this ConnectionPool has been closed
        See Also:
        ConnectionPool.close()
      • isMaximizeConnections

        @ManagedAttribute("Whether the pool tries to maximize the number of connections used")
        public boolean isMaximizeConnections()
      • setMaximizeConnections

        public void setMaximizeConnections​(boolean maximizeConnections)

        Sets whether the number of connections should be maximized.

        Parameters:
        maximizeConnections - whether the number of connections should be maximized
      • acquire

        public Connection acquire()
        Description copied from interface: ConnectionPool

        Returns an idle connection, if available, or schedules the opening of a new connection and returns null.

        Specified by:
        acquire in interface ConnectionPool
        Returns:
        an available connection, or null
      • acquire

        protected Connection acquire​(boolean create)

        Returns an idle connection, if available; if an idle connection is not available, and the given create parameter is true or isMaximizeConnections() is true, then attempts to open a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise it attempts to open a new connection, if the number of queued requests is greater than the number of pending connections; if no connection is available even after the attempts to open, return null.

        The create parameter is just a hint: the connection may be created even if false, or may not be created even if true.

        Parameters:
        create - a hint to attempt to open a new connection if no idle connections are available
        Returns:
        an idle connection or null if no idle connections are available
        See Also:
        tryCreate(boolean)
      • tryCreate

        protected void tryCreate​(boolean create)

        Tries to create a new connection.

        Whether a new connection is created is determined by the create parameter and a count of demand and supply, where the demand is derived from the number of queued requests, and the supply is the number of pending connections time the getMaxMultiplex() factor: if the demand is less than the supply, the connection will not be created.

        Since the number of queued requests used to derive the demand may be a stale value, it is possible that few more connections than strictly necessary may be created, but enough to satisfy the demand.

        Parameters:
        create - a hint to request to create a connection
      • proceed

        protected void proceed()
      • isActive

        public boolean isActive​(Connection connection)
        Specified by:
        isActive in interface ConnectionPool
        Parameters:
        connection - the connection to test
        Returns:
        whether the given connection is currently in use
      • release

        public boolean release​(Connection connection)
        Description copied from interface: ConnectionPool

        Returns the given connection, previously obtained via ConnectionPool.acquire(), back to this ConnectionPool.

        Specified by:
        release in interface ConnectionPool
        Parameters:
        connection - the connection to release
        Returns:
        true if the connection has been released, false if the connection should be closed
      • deactivate

        protected boolean deactivate​(Connection connection)
      • remove

        public boolean remove​(Connection connection)
        Description copied from interface: ConnectionPool

        Removes the given connection from this ConnectionPool.

        Specified by:
        remove in interface ConnectionPool
        Parameters:
        connection - the connection to remove
        Returns:
        true if the connection was removed from this ConnectionPool
      • remove

        @Deprecated
        protected boolean remove​(Connection connection,
                                 boolean force)
        Deprecated.
      • onCreated

        protected void onCreated​(Connection connection)
      • idle

        protected boolean idle​(Connection connection,
                               boolean close)
      • acquired

        protected void acquired​(Connection connection)
      • released

        protected void released​(Connection connection)
      • removed

        protected void removed​(Connection connection)
      • getIdleConnections

        @Deprecated
        public java.util.Queue<Connection> getIdleConnections()
        Deprecated.
        Relying on this method indicates a reliance on the implementation details.
        Returns:
        an unmodifiable queue working as a view of the idle connections.
      • getActiveConnections

        @Deprecated
        public java.util.Collection<Connection> getActiveConnections()
        Deprecated.
        Relying on this method indicates a reliance on the implementation details.
        Returns:
        an unmodifiable collection working as a view of the active connections.
      • close

        public void close()
        Description copied from interface: ConnectionPool
        Closes this ConnectionPool.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface ConnectionPool
        See Also:
        ConnectionPool.isClosed()
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Specified by:
        dump in interface org.eclipse.jetty.util.component.Dumpable
        Overrides:
        dump in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        java.io.IOException
      • sweep

        public boolean sweep()
        Specified by:
        sweep in interface org.eclipse.jetty.util.thread.Sweeper.Sweepable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class org.eclipse.jetty.util.component.AbstractLifeCycle