@ManagedObject public abstract class AbstractConnectionPool extends java.lang.Object implements ConnectionPool, Dumpable
ConnectionPool.Factory, ConnectionPool.Multiplexable
Modifier and Type | Field and 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 |
Modifier | Constructor and Description |
---|---|
protected |
AbstractConnectionPool(Destination destination,
int maxConnections,
Callback requester)
Deprecated.
|
protected |
AbstractConnectionPool(HttpDestination destination,
int maxConnections,
Callback requester) |
Modifier and Type | Method and 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 ,
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 returns null . |
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.
use
getPendingConnectionCount() instead |
protected 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isActive, release, remove
dump, dump, dumpContainer, dumpIterable, dumpMapEntries, dumpObject, dumpObjects, dumpSelf, named
private static final Logger LOG
private final AtomicBiInteger connections
private final java.util.concurrent.atomic.AtomicBoolean closed
private final HttpDestination destination
private final int maxConnections
private final Callback requester
@Deprecated protected AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
AbstractConnectionPool(HttpDestination, int, Callback)
insteaddestination
- the correspondent destinationmaxConnections
- the max number of connectionsrequester
- the callback to notify about new connection creation/failureprotected AbstractConnectionPool(HttpDestination destination, int maxConnections, Callback requester)
protected HttpDestination getHttpDestination()
@ManagedAttribute(value="The max number of connections", readonly=true) public int getMaxConnectionCount()
@ManagedAttribute(value="The number of connections", readonly=true) public int getConnectionCount()
@ManagedAttribute(value="The number of pending connections", readonly=true) @Deprecated public int getPendingCount()
getPendingConnectionCount()
instead@ManagedAttribute(value="The number of pending connections", readonly=true) public int getPendingConnectionCount()
public boolean isEmpty()
isEmpty
in interface ConnectionPool
public boolean isClosed()
isClosed
in interface ConnectionPool
ConnectionPool.close()
public Connection acquire()
ConnectionPool
Returns an idle connection, if available, or schedules the opening
of a new connection and returns null
.
acquire
in interface ConnectionPool
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
,
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 returns null
.
create
- whether to schedule the opening of a connection if no idle connections are availablenull
if no idle connections are availabletryCreate(int)
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:
if maxPending
is greater than the current number of connections scheduled for opening,
then this method returns without scheduling the opening of a new connection;
if maxPending
is negative, a new connection is always scheduled for opening.
maxPending
- the max desired number of connections scheduled for opening,
or a negative number to always trigger the opening of a new connectionprotected abstract void onCreated(Connection connection)
protected void proceed()
protected abstract Connection activate()
protected Connection active(Connection connection)
protected void acquired(Connection connection)
protected boolean idle(Connection connection, boolean close)
protected void released(Connection connection)
protected void removed(Connection connection)
public void close()
ConnectionPool
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface ConnectionPool
ConnectionPool.isClosed()
protected void close(java.util.Collection<Connection> connections)