@ManagedObject public abstract class AbstractConnectionPool extends java.lang.Object implements ConnectionPool, Dumpable
ConnectionPool.Factory
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 Destination |
destination |
private static Logger |
LOG |
private int |
maxConnections |
private Callback |
requester |
Modifier | Constructor and Description |
---|---|
protected |
AbstractConnectionPool(Destination 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 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() |
int |
getMaxConnectionCount() |
int |
getPendingCount() |
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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isActive, release, remove
private static final Logger LOG
private final java.util.concurrent.atomic.AtomicBoolean closed
private final AtomicBiInteger connections
private final Destination destination
private final int maxConnections
private final Callback requester
protected AbstractConnectionPool(Destination destination, int maxConnections, Callback requester)
@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) public int getPendingCount()
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 void tryCreate(int maxPending)
protected 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)