-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
- All Known Implementing Classes:
AbstractConnectionPool
,DuplexConnectionPool
,LeakTrackingConnectionPool
,MultiplexConnectionPool
,RandomConnectionPool
,RoundRobinConnectionPool
,ValidatingConnectionPool
public interface ConnectionPool extends java.io.Closeable
Client-side connection pool abstraction.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ConnectionPool.Factory
Factory for ConnectionPool instances.static interface
ConnectionPool.Multiplexable
Marks a connection pool as supporting multiplexed connections.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
accept(Connection connection)
Accepts the given connection to be managed by this ConnectionPool.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
.void
close()
boolean
isActive(Connection connection)
boolean
isClosed()
boolean
isEmpty()
default java.util.concurrent.CompletableFuture<java.lang.Void>
preCreateConnections(int connectionCount)
Optionally pre-create up toconnectionCount
connections so they are immediately ready for use.boolean
release(Connection connection)
Returns the given connection, previously obtained viaacquire(boolean)
, back to this ConnectionPool.boolean
remove(Connection connection)
Removes the given connection from this ConnectionPool.
-
-
-
Method Detail
-
preCreateConnections
default java.util.concurrent.CompletableFuture<java.lang.Void> preCreateConnections(int connectionCount)
Optionally pre-create up toconnectionCount
connections so they are immediately ready for use.- Parameters:
connectionCount
- the number of connections to pre-start.
-
isActive
boolean isActive(Connection connection)
- Parameters:
connection
- the connection to test- Returns:
- whether the given connection is currently in use
-
isEmpty
boolean isEmpty()
- Returns:
- whether this ConnectionPool has no open connections
-
isClosed
boolean isClosed()
- Returns:
- whether this ConnectionPool has been closed
- See Also:
close()
-
acquire
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
-
accept
boolean accept(Connection connection)
Accepts the given connection to be managed by this ConnectionPool.
- Parameters:
connection
- the connection to accept- Returns:
- whether the connection has been accepted
-
release
boolean release(Connection connection)
Returns the given connection, previously obtained via
acquire(boolean)
, back to this ConnectionPool.- Parameters:
connection
- the connection to release- Returns:
- true if the connection has been released, false if the connection should be closed
-
remove
boolean remove(Connection connection)
Removes the given connection from this ConnectionPool.
- Parameters:
connection
- the connection to remove- Returns:
- true if the connection was removed from this ConnectionPool
-
close
void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-