Class AbstractConnectionPool
- java.lang.Object
-
- org.eclipse.jetty.client.AbstractConnectionPool
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ConnectionPool
,Dumpable
- Direct Known Subclasses:
DuplexConnectionPool
,MultiplexConnectionPool
,RoundRobinConnectionPool
@ManagedObject public abstract class AbstractConnectionPool extends java.lang.Object implements ConnectionPool, Dumpable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.ConnectionPool
ConnectionPool.Factory, ConnectionPool.Multiplexable
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
closed
private AtomicBiInteger
connections
The connectionCount encodes both the total connections plus the pending connection counts, so both can be atomically changed.private HttpDestination
destination
private static Logger
LOG
private int
maxConnections
private Callback
requester
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
Deprecated.protected
AbstractConnectionPool(HttpDestination destination, int maxConnections, Callback requester)
-
Method Summary
All Methods Instance Methods Abstract 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 returnsnull
.protected Connection
acquire(boolean create)
Returns an idle connection, if available; if an idle connection is not available, and the givencreate
parameter istrue
, then schedules the opening of a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise returnsnull
.protected void
acquired(Connection connection)
protected abstract Connection
activate()
protected Connection
active(Connection connection)
void
close()
Closes this ConnectionPool.protected void
close(java.util.Collection<Connection> connections)
java.lang.String
dump()
int
getConnectionCount()
protected HttpDestination
getHttpDestination()
int
getMaxConnectionCount()
int
getPendingConnectionCount()
int
getPendingCount()
Deprecated.usegetPendingConnectionCount()
insteadprotected boolean
idle(Connection connection, boolean close)
boolean
isClosed()
boolean
isEmpty()
protected abstract void
onCreated(Connection connection)
protected void
proceed()
protected void
released(Connection connection)
protected void
removed(Connection connection)
protected void
tryCreate(int maxPending)
Schedules the opening of a new connection.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.client.ConnectionPool
isActive, release, remove
-
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
connections
private final AtomicBiInteger connections
The connectionCount encodes both the total connections plus the pending connection counts, so both can be atomically changed. The bottom 32 bits represent the total connections and the top 32 bits represent the pending connections.
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
destination
private final HttpDestination destination
-
maxConnections
private final int maxConnections
-
requester
private final Callback requester
-
-
Constructor Detail
-
AbstractConnectionPool
@Deprecated protected AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
Deprecated.- Parameters:
destination
- the correspondent destinationmaxConnections
- the max number of connectionsrequester
- the callback to notify about new connection creation/failure
-
AbstractConnectionPool
protected AbstractConnectionPool(HttpDestination destination, int maxConnections, Callback requester)
-
-
Method Detail
-
getHttpDestination
protected HttpDestination getHttpDestination()
-
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.usegetPendingConnectionCount()
instead- 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 interfaceConnectionPool
- Returns:
- whether this ConnectionPool has no open connections
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in interfaceConnectionPool
- Returns:
- whether this ConnectionPool has been closed
- See Also:
ConnectionPool.close()
-
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 interfaceConnectionPool
- 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 istrue
, then schedules the opening of a new connection, if possible within the configuration of this connection pool (for example, if it does not exceed the max connection count); otherwise returnsnull
.- Parameters:
create
- whether to schedule the opening of a connection if no idle connections are available- Returns:
- an idle connection or
null
if no idle connections are available - See Also:
tryCreate(int)
-
tryCreate
protected void tryCreate(int maxPending)
Schedules the opening of a new connection.
Whether a new connection is scheduled for opening is determined by the
maxPending
parameter: ifmaxPending
is greater than the current number of connections scheduled for opening, then this method returns without scheduling the opening of a new connection; ifmaxPending
is negative, a new connection is always scheduled for opening.- Parameters:
maxPending
- the max desired number of connections scheduled for opening, or a negative number to always trigger the opening of a new connection
-
onCreated
protected abstract void onCreated(Connection connection)
-
proceed
protected void proceed()
-
activate
protected abstract Connection activate()
-
active
protected Connection active(Connection connection)
-
acquired
protected void acquired(Connection connection)
-
idle
protected boolean idle(Connection connection, boolean close)
-
released
protected void released(Connection connection)
-
removed
protected void removed(Connection connection)
-
close
public void close()
Description copied from interface:ConnectionPool
Closes this ConnectionPool.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceConnectionPool
- See Also:
ConnectionPool.isClosed()
-
close
protected void close(java.util.Collection<Connection> connections)
-
-