E - the address type, for example for TCP transport it's SocketAddresspublic class MultiEndpointPool<E> extends Object
Connection pool implementation where each endpoint sub-pool is represented by
SingleEndpointPool and referenced by an Endpoint.
There are number of configuration options supported by the MultiEndpointPool: -
maxConnectionsPerEndpoint: the maximum number of Connections each SingleEndpointPool
sub-pool is allowed to have; - maxConnectionsTotal: the total maximum number of Connections to be
kept by the pool; - keepAliveTimeoutMillis: the maximum number of milliseconds an idle Connection
will be kept in the pool. The idle Connections will be closed until the pool size is greater than the
corePoolSize; - keepAliveCheckIntervalMillis: the interval, which specifies how often the pool will
perform idle Connections check; - reconnectDelayMillis: the delay to be used before the pool will
repeat the attempt to connect to the endpoint after previous connect had failed. - asyncPollTimeoutMillis:
maximum amount of time, after which the async connection poll operation will be failed with a timeout exception -
connectionTTLMillis: the maximum amount of time, a Connection could be associated with the pool| Modifier and Type | Class and Description |
|---|---|
static class |
MultiEndpointPool.Builder<E>
The Builder class responsible for constructing
SingleEndpointPool. |
static class |
MultiEndpointPool.EndpointPoolBuilder<E> |
static interface |
MultiEndpointPool.EndpointPoolCustomizer<E>
The customizer, which could be used to modify an endpoint pool setting before it will be created.
|
| Modifier and Type | Field and Description |
|---|---|
protected Map<Endpoint<E>,SingleEndpointPool<E>> |
endpointToPoolMap
Maps endpoint -to- SingleEndpointPool
|
protected Object |
poolSync
Sync for endpointToPoolMap updates
|
| Modifier | Constructor and Description |
|---|---|
protected |
MultiEndpointPool(org.glassfish.grizzly.ConnectorHandler<E> defaultConnectorHandler,
int maxConnectionsPerEndpoint,
int maxConnectionsTotal,
org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor,
long connectTimeoutMillis,
long keepAliveTimeoutMillis,
long keepAliveCheckIntervalMillis,
long reconnectDelayMillis,
int maxReconnectAttempts,
long asyncPollTimeoutMillis,
long connectionTTLMillis,
boolean failFastWhenMaxSizeReached,
MultiEndpointPool.EndpointPoolCustomizer<E> endpointPoolCustomizer)
Deprecated.
defaultConnectorHandler is deprecated
|
protected |
MultiEndpointPool(int maxConnectionsPerEndpoint,
int maxConnectionsTotal,
org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor,
long connectTimeoutMillis,
long keepAliveTimeoutMillis,
long keepAliveCheckIntervalMillis,
long reconnectDelayMillis,
int maxReconnectAttempts,
long asyncPollTimeoutMillis,
long connectionTTLMillis,
boolean failFastWhenMaxSizeReached,
MultiEndpointPool.EndpointPoolCustomizer<E> endpointPoolCustomizer)
Constructs MultiEndpointPool instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
attach(Endpoint<E> endpoint,
org.glassfish.grizzly.Connection connection)
Attaches "foreign"
Connection to the pool. |
static <T> MultiEndpointPool.Builder<T> |
builder(Class<T> endpointType)
Returns single endpoint pool
MultiEndpointPool.Builder. |
protected void |
checkNotClosed()
Method throws
IOException if the pool has been closed. |
void |
close()
Closes the pool and releases associated resources.
|
void |
close(Endpoint<E> endpoint)
Closes specific endpoint associated pool and releases its resources.
|
protected SingleEndpointPool<E> |
createSingleEndpointPool(Endpoint<E> endpoint)
Creates
SingleEndpointPool instance. |
boolean |
detach(org.glassfish.grizzly.Connection connection)
Detaches a
Connection from the pool. |
long |
getAsyncPollTimeout(TimeUnit timeUnit) |
ConnectionInfo<E> |
getConnectionInfo(org.glassfish.grizzly.Connection connection)
Returns pooled
ConnectionInfo, that might be used for monitoring reasons, or null if the
Connection does not belong to this pool. |
long |
getConnectionTTL(TimeUnit timeUnit)
Return the maximum amount of time, a
Connection could be associated with the pool. |
long |
getConnectTimeout(TimeUnit timeUnit) |
long |
getKeepAliveCheckInterval(TimeUnit timeUnit) |
long |
getKeepAliveTimeout(TimeUnit timeUnit)
Returns the maximum amount of time an idle
Connection will be kept in the pool. |
int |
getMaxConnectionsPerEndpoint() |
int |
getMaxConnectionsTotal() |
int |
getMaxReconnectAttempts() |
int |
getOpenConnectionsCount() |
long |
getReconnectDelay(TimeUnit timeUnit) |
boolean |
isBusy(org.glassfish.grizzly.Connection connection)
Returns true only if the
Connection is registered in the pool and is currently in busy state (used
by a user), otherwise returns false. |
boolean |
isFailFastWhenMaxSizeReached() |
boolean |
isMaxCapacityReached() |
boolean |
isRegistered(org.glassfish.grizzly.Connection connection)
Returns true if the
Connection is registered in the pool no matter if it's currently in busy or
ready state, or false if the Connection is not registered in the pool. |
protected SingleEndpointPool<E> |
obtainSingleEndpointPool(Endpoint<E> endpoint)
Obtains
SingleEndpointPool associated with the specific endpoint represented by Endpoint. |
org.glassfish.grizzly.Connection |
poll(Endpoint<E> endpoint) |
boolean |
release(org.glassfish.grizzly.Connection connection)
Returns the
Connection to the pool. |
int |
size() |
org.glassfish.grizzly.GrizzlyFuture<org.glassfish.grizzly.Connection> |
take(Endpoint<E> endpoint)
Obtains a
Connection to the specified endpoint from the pool in non-blocking/asynchronous fashion. |
void |
take(Endpoint<E> endpoint,
org.glassfish.grizzly.CompletionHandler<org.glassfish.grizzly.Connection> completionHandler)
Obtains a
Connection to the specified endpoint from the pool in non-blocking/asynchronous fashion. |
String |
toString() |
protected final Map<Endpoint<E>,SingleEndpointPool<E>> endpointToPoolMap
protected final Object poolSync
@Deprecated protected MultiEndpointPool(org.glassfish.grizzly.ConnectorHandler<E> defaultConnectorHandler, int maxConnectionsPerEndpoint, int maxConnectionsTotal, org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor, long connectTimeoutMillis, long keepAliveTimeoutMillis, long keepAliveCheckIntervalMillis, long reconnectDelayMillis, int maxReconnectAttempts, long asyncPollTimeoutMillis, long connectionTTLMillis, boolean failFastWhenMaxSizeReached, MultiEndpointPool.EndpointPoolCustomizer<E> endpointPoolCustomizer)
defaultConnectorHandler - the default ConnectorHandler to be used to establish new ConnectionsmaxConnectionsPerEndpoint - the maximum number of Connections single endpoint sub-pool is allowed to
havemaxConnectionsTotal - the total maximum number of Connections the pool is allowed to havedelayedExecutor - custom DelayedExecutor to be used by keep-alive and reconnect mechanismsconnectTimeoutMillis - timeout, after which, if a connection is not established, it is considered failedkeepAliveTimeoutMillis - the maximum number of milliseconds an idle Connection will be kept in the poolkeepAliveCheckIntervalMillis - the interval, which specifies how often the pool will perform idle
Connections checkreconnectDelayMillis - the delay to be used before the pool will repeat the attempt to connect to the endpoint
after previous connect had failedmaxReconnectAttempts - the maximum number of reconnect attempts that may be made before failure notification.asyncPollTimeoutMillis - the maximum time, the async poll operation could wait for a connection to become
availableconnectionTTLMillis - the maximum time, a connection could stay registered with the poolfailFastWhenMaxSizeReached - true if the "take" method should fail fast if there is no free connection
in the pool and max pool size is reachedendpointPoolCustomizer - the customizer, which will be used to modify a specific endpoint pool settings and
overwrite the default settings assigned by this MultiEndpointPoolprotected MultiEndpointPool(int maxConnectionsPerEndpoint,
int maxConnectionsTotal,
org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor,
long connectTimeoutMillis,
long keepAliveTimeoutMillis,
long keepAliveCheckIntervalMillis,
long reconnectDelayMillis,
int maxReconnectAttempts,
long asyncPollTimeoutMillis,
long connectionTTLMillis,
boolean failFastWhenMaxSizeReached,
MultiEndpointPool.EndpointPoolCustomizer<E> endpointPoolCustomizer)
maxConnectionsPerEndpoint - the maximum number of Connections single endpoint sub-pool is allowed to
havemaxConnectionsTotal - the total maximum number of Connections the pool is allowed to havedelayedExecutor - custom DelayedExecutor to be used by keep-alive and reconnect mechanismsconnectTimeoutMillis - timeout, after which, if a connection is not established, it is considered failedkeepAliveTimeoutMillis - the maximum number of milliseconds an idle Connection will be kept in the poolkeepAliveCheckIntervalMillis - the interval, which specifies how often the pool will perform idle
Connections checkreconnectDelayMillis - the delay to be used before the pool will repeat the attempt to connect to the endpoint
after previous connect had failedmaxReconnectAttempts - the maximum number of reconnect attempts that may be made before failure notification.asyncPollTimeoutMillis - the maximum time, the async poll operation could wait for a connection to become
availableconnectionTTLMillis - the maximum time, a connection could stay registered with the poolfailFastWhenMaxSizeReached - true if the "take" method should fail fast if there is no free connection
in the pool and max pool size is reachedendpointPoolCustomizer - the customizer, which will be used to modify a specific endpoint pool settings and
overwrite the default settings assigned by this MultiEndpointPoolpublic static <T> MultiEndpointPool.Builder<T> builder(Class<T> endpointType)
MultiEndpointPool.Builder.T - endpoint typeendpointType - endpoint address type, for example SocketAddress for TCP and UDP transportsMultiEndpointPool.Builderpublic int getMaxConnectionsTotal()
Connections to be kept by the poolpublic int getMaxConnectionsPerEndpoint()
Connections each SingleEndpointPool sub-pool is allowed to havepublic long getConnectTimeout(TimeUnit timeUnit)
timeUnit - TimeUnitpublic long getReconnectDelay(TimeUnit timeUnit)
timeUnit - TimeUnitpublic int getMaxReconnectAttempts()
public long getKeepAliveTimeout(TimeUnit timeUnit)
Connection will be kept in the pool.timeUnit - TimeUnitConnection will be kept in the poolpublic long getKeepAliveCheckInterval(TimeUnit timeUnit)
timeUnit - TimeUnitConnections checkpublic long getAsyncPollTimeout(TimeUnit timeUnit)
timeUnit - TimeUnitpublic long getConnectionTTL(TimeUnit timeUnit)
Connection could be associated with the pool. Once timeout is hit - the
connection will be either closed, if it's idle, or detached from the pool, if it's being used.timeUnit - TimeUnitConnection could be associated with the poolpublic boolean isFailFastWhenMaxSizeReached()
public int size()
Connectionspublic int getOpenConnectionsCount()
Connections in the pool. Unlike size() the value doesn't include
connecting (connect in progress) Connectionspublic boolean isMaxCapacityReached()
Connections the pool can keep is reached and no new
Connection can be established, or false otherwise.public boolean isRegistered(org.glassfish.grizzly.Connection connection)
Connection is registered in the pool no matter if it's currently in busy or
ready state, or false if the Connection is not registered in the pool.connection - ConnectionConnection is registered in the pool no matter if it's currently in busy or
ready state, or false if the Connection is not registered in the poolpublic boolean isBusy(org.glassfish.grizzly.Connection connection)
Connection is registered in the pool and is currently in busy state (used
by a user), otherwise returns false.connection - ConnectionConnection is registered in the pool and is currently in busy state (used
by a user), otherwise returns falsepublic ConnectionInfo<E> getConnectionInfo(org.glassfish.grizzly.Connection connection)
ConnectionInfo, that might be used for monitoring reasons, or null if the
Connection does not belong to this pool.connection - ConnectionConnectionInfo, that might be used for monitoring reasons, or null if the
Connection does not belong to this poolpublic org.glassfish.grizzly.GrizzlyFuture<org.glassfish.grizzly.Connection> take(Endpoint<E> endpoint)
Connection to the specified endpoint from the pool in non-blocking/asynchronous fashion.
Returns a GrizzlyFuture representing the pending result of the non-blocking/asynchronous obtain task.
Future's get method will return the Connection once it becomes available in the pool.
If you would like to immediately block waiting for a Connection, you can use constructions of the form
connection = pool.take(endpoint).get();
Note: returned GrizzlyFuture must be checked and released properly. It must not be forgotten, because a
Connection, that might be assigned as a result of GrizzlyFuture has to be returned to the pool. If
you gave up on waiting for a Connection or you are not interested in the Connection anymore, the
proper release code has to look like:
if (!future.cancel(false)) {
// means Connection is ready
pool.release(future.get());
}
endpoint - Endpoint, that represents an endpointGrizzlyFuturepublic void take(Endpoint<E> endpoint, org.glassfish.grizzly.CompletionHandler<org.glassfish.grizzly.Connection> completionHandler)
Connection to the specified endpoint from the pool in non-blocking/asynchronous fashion. The passed
CompletionHandler will be notified about the result of the non-blocking/asynchronous obtain task.endpoint - Endpoint, that represents an endpointcompletionHandler - public org.glassfish.grizzly.Connection poll(Endpoint<E> endpoint) throws IOException
endpoint - Endpoint, that represents an endpointConnection from the pool, if there is one available at the moment, or null otherwiseIOException - if the pool is closedpublic boolean release(org.glassfish.grizzly.Connection connection)
Connection to the pool.
The Connection will be returned to the pool only in case it was created by this pool, or it was attached to
it using attach(Endpoint, org.glassfish.grizzly.Connection) method. If the Connection is not
registered in the pool - it will be closed. If the Connection is registered in the pool and already marked as
ready - this method call will not have any effect.
If the Connection was returned - it is illegal to use it until it is retrieved from the pool again.connection - the Connection to returntrue if the connection was successfully released. If the connection cannot be released, the
connection will be closed and false will be returned.public boolean attach(Endpoint<E> endpoint, org.glassfish.grizzly.Connection connection) throws IOException
Connection to the pool. This method might be used to add to the pool a Connection,
that either has not been created by this pool or has been detached.endpoint - Endpoint, that represents an endpoint to which the the Connection will be attachedconnection - ConnectionConnection has been successfully attached, or false otherwise. If the
Connection had been already registered in the pool - the method call doesn't have any effect and
true will be returned.IOException - thrown if this pool has been already closedpublic boolean detach(org.glassfish.grizzly.Connection connection)
Connection from the pool. De-registers the Connection from the pool and decreases the pool
size by 1. It is possible to re-attach the detached Connection later by calling
attach(org.glassfish.grizzly.connectionpool.Endpoint, org.glassfish.grizzly.Connection).
If the Connection was not registered in the pool - the method call doesn't have any effect.connection - the Connection to detachtrue if the Connection was detached, otherwise returns falsepublic void close(Endpoint<E> endpoint)
Connections associated with the endpoint pool will be closed, the busy Connection, that are
still in use - will be kept open and will be automatically closed when returned to the pool by
release(org.glassfish.grizzly.Connection).endpoint - Endpoint, that represents an endpointpublic void close()
Connections will be closed, the busy Connection, that are still in use - will be kept open
and will be automatically closed when returned to the pool by release(org.glassfish.grizzly.Connection).protected SingleEndpointPool<E> obtainSingleEndpointPool(Endpoint<E> endpoint) throws IOException
SingleEndpointPool associated with the specific endpoint represented by Endpoint. If there is
no SingleEndpointPool associated with the endpoint - the one will be created.endpoint - Endpoint, that represents an endpointSingleEndpointPoolIOException - if the pool is already closedprotected SingleEndpointPool<E> createSingleEndpointPool(Endpoint<E> endpoint)
SingleEndpointPool instance.endpoint - the endpoint keySingleEndpointPoolprotected void checkNotClosed()
throws IOException
IOException if the pool has been closed.IOException - if the pool has been closedCopyright © 2017–2020 Oracle Corporation. All rights reserved.