Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.connectionpool

public Class MultiEndpointPool<E>

extends Object
Class Inheritance
Type Parameters
<E>
the address type, for example for TCP transport it's SocketAddress
Imports
java.io.IOException, java.net.SocketAddress, java.util.Map, java.util.concurrent.ConcurrentHashMap, .ExecutorService, .Future, .TimeUnit, .TimeoutException, java.util.logging.Level, .Logger, org.glassfish.grizzly.CompletionHandler, .Connection, .ConnectorHandler, .Grizzly, .GrizzlyFuture, org.glassfish.grizzly.connectionpool.SingleEndpointPool.AsyncPoll, .SingleEndpointPool.AsyncPollTimeoutTaskResolver, .SingleEndpointPool.AsyncPollTimeoutWorker, .SingleEndpointPool.ConnectTimeoutTask, .SingleEndpointPool.ConnectTimeoutTaskResolver, .SingleEndpointPool.ConnectTimeoutWorker, .SingleEndpointPool.ConnectionTTLTaskResolver, .SingleEndpointPool.ConnectionTTLWorker, .SingleEndpointPool.KeepAliveCleaner, .SingleEndpointPool.KeepAliveCleanerTask, .SingleEndpointPool.KeepAliveCleanerTaskResolver, .SingleEndpointPool.ReconnectTask, .SingleEndpointPool.ReconnectTaskResolver, .SingleEndpointPool.Reconnector, org.glassfish.grizzly.threadpool.GrizzlyExecutorService, .ThreadPoolConfig, org.glassfish.grizzly.utils.DelayedExecutor, .DelayedExecutor.DelayQueue, .Futures

The multi endpoint 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
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
MultiEndpointPool.Builder<
endpoint address type, for example java.net.SocketAddress for TCP and UDP transports
E
>

The Builder class responsible for constructing SingleEndpointPool.

public static class
public static interface
MultiEndpointPool.EndpointPoolCustomizer<
the address type, for example for TCP transport it's SocketAddress
E
>

The customizer, which could be used to modify an endpoint pool setting before it will be created.

private class
MultiEndpointPool.EndpointPoolImpl

SingleEndpointPool implementation used by this MultiEndpointPool.

Field Summary

Modifier and TypeField and Description
private final long
asyncPollTimeoutMillis

Async poll timeout, after which, the async connection poll operation will be failed with a timeout exception

private DelayedExecutor.DelayQueue<Link<SingleEndpointPool.AsyncPoll>>
asyncPollTimeoutQueue

DelayQueue for async poll timeout mechanism

private final Map<Connection<L>, ConnectionInfo<E>>
connectionToSubPoolMap

Maps Connection -to- ConnectionInfo

private final long
connectionTTLMillis

the maximum amount of time, a Connection could stay registered 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.

private DelayedExecutor.DelayQueue<ConnectionInfo<E>>
connectionTTLQueue

DelayQueue for connection time to live mechanism

private final long
connectTimeoutMillis

Connect timeout, after which, if a connection is not established, it is considered failed

private DelayedExecutor.DelayQueue<SingleEndpointPool.ConnectTimeoutTask>
connectTimeoutQueue

DelayQueue for connect timeout mechanism

private final Object
countersSync

The pool's counters sync (poolSize, totalPendingConnections etc)

private final ConnectorHandler<E>
defaultConnectorHandler

The default ConnectorHandler used to establish new Connections is none is specified by EndpointKey

private final DelayedExecutor
delayedExecutor

The DelayedExecutor either own or provided, used for keep-alive, re-connect or other timeout related mechanisms.

private final MultiEndpointPool.EndpointPoolCustomizer<E>
endpointPoolCustomizer

The customizer, which will be used to modify a specific endpoint pool settings and overwrite the default settings assigned by this MultiEndpointPool.

protected final Map<Endpoint<E>, SingleEndpointPool<E>>
endpointToPoolMap

Maps endpoint -to- SingleEndpointPool

private final boolean
failFastWhenMaxSizeReached

if true, the "take" method will fail fast if there is no free connection in the pool and max pool size is reached.

private boolean
isClosed

close flag

private final long
keepAliveCheckIntervalMillis

the interval, which specifies how often the pool will perform idle Connections check

private DelayedExecutor.DelayQueue<SingleEndpointPool.KeepAliveCleanerTask<E>>
keepAliveCleanerQueue

DelayQueue for keep-alive mechanism

private final long
keepAliveTimeoutMillis

the maximum number of milliseconds an idle Connection will be kept in the pool.

private static final Logger
private final int
maxConnectionsPerEndpoint

the maximum number of Connections each SingleEndpointPool sub-pool is allowed to have

private final int
maxConnectionsTotal

the total maximum number of Connections to be kept by the pool

private final Chain<MultiEndpointPool<E>.EndpointPoolImpl>
maxPoolSizeHitsChain

Priority queue, that helps to distribute connections fairly in situation when the max number of connections is reached

private final int
maxReconnectAttempts

Maximum number of reconnect attempts.

private final DelayedExecutor
ownDelayedExecutor

Own/internal DelayedExecutor to be used for keep-alive and reconnect mechanisms, if one (DelayedExecutor} was not specified by user

private final ExecutorService
ownDelayedExecutorThreadPool

The thread-pool used by theownDelayedExecutor

private int
poolSize

current pool size

protected final Object
poolSync

Sync for endpointToPoolMap updates

private final long
reconnectDelayMillis

the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect had failed

private DelayedExecutor.DelayQueue<SingleEndpointPool.ReconnectTask<E>>
reconnectQueue

DelayQueue for reconnect mechanism

private int
totalPendingConnections

Number of connections we're currently trying to establish and waiting for the result

Constructor Summary

AccessConstructor and Description
protected
MultiEndpointPool(final ConnectorHandler<E>
the default ConnectorHandler to be used to establish new Connections
defaultConnectorHandler
,
final int
the maximum number of Connections single endpoint sub-pool is allowed to have
maxConnectionsPerEndpoint
,
final int
the total maximum number of Connections the pool is allowed to have
maxConnectionsTotal
,
DelayedExecutor
custom DelayedExecutor to be used by keep-alive and reconnect mechanisms
delayedExecutor
,
final long
timeout, after which, if a connection is not established, it is considered failed
connectTimeoutMillis
,
final long
the maximum number of milliseconds an idle Connection will be kept in the pool
keepAliveTimeoutMillis
,
final long
the interval, which specifies how often the pool will perform idle Connections check
keepAliveCheckIntervalMillis
,
final long
the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect had failed
reconnectDelayMillis
,
final int
the maximum number of reconnect attempts that may be made before failure notification.
maxReconnectAttempts
,
final long
the maximum time, the async poll operation could wait for a connection to become available
asyncPollTimeoutMillis
,
final long
the maximum time, a connection could stay registered with the pool
connectionTTLMillis
,
final boolean
true if the "take" method should fail fast if there is no free connection in the pool and max pool size is reached
failFastWhenMaxSizeReached
,
final MultiEndpointPool.EndpointPoolCustomizer<E>
the customizer, which will be used to modify a specific endpoint pool settings and overwrite the default settings assigned by this MultiEndpointPool
endpointPoolCustomizer
)
Deprecated defaultConnectorHandler is deprecated

Constructs MultiEndpointPool instance.

protected
MultiEndpointPool(final int
the maximum number of Connections single endpoint sub-pool is allowed to have
maxConnectionsPerEndpoint
,
final int
the total maximum number of Connections the pool is allowed to have
maxConnectionsTotal
,
final DelayedExecutor
custom DelayedExecutor to be used by keep-alive and reconnect mechanisms
delayedExecutor
,
final long
timeout, after which, if a connection is not established, it is considered failed
connectTimeoutMillis
,
final long
the maximum number of milliseconds an idle Connection will be kept in the pool
keepAliveTimeoutMillis
,
final long
the interval, which specifies how often the pool will perform idle Connections check
keepAliveCheckIntervalMillis
,
final long
the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect had failed
reconnectDelayMillis
,
final int
the maximum number of reconnect attempts that may be made before failure notification.
maxReconnectAttempts
,
final long
the maximum time, the async poll operation could wait for a connection to become available
asyncPollTimeoutMillis
,
final long
the maximum time, a connection could stay registered with the pool
connectionTTLMillis
,
final boolean
true if the "take" method should fail fast if there is no free connection in the pool and max pool size is reached
failFastWhenMaxSizeReached
,
final MultiEndpointPool.EndpointPoolCustomizer<E>
the customizer, which will be used to modify a specific endpoint pool settings and overwrite the default settings assigned by this MultiEndpointPool
endpointPoolCustomizer
)

Constructs MultiEndpointPool instance.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the Connection 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.
attach
(final Endpoint<E>
Endpoint, that represents an endpoint to which the the Connection will be attached
endpoint
,
final Connection<L> connection)

Attaches "foreign" Connection to the pool.

public static <
endpoint type
T
>
MultiEndpointPool.Builder<T>

Returns:

Builder
builder
(Class<T>
endpoint address type, for example java.net.SocketAddress for TCP and UDP transports
endpointType
)

Returns single endpoint pool Builder.

private void
checkAsyncPollTimeoutQueue(final long asyncPollTimeoutMillis)

private void
checkConnectionTTLQueue(final long connectionTTLMillis)

private void
checkConnectTimeoutQueue(final long connectTimeoutMillis)

private void
checkKeepAliveCleanerQueue(final long keepAliveTimeoutMillis)

protected void
checkNotClosed()

Method throws IOException if the pool has been closed.

private void
checkReconnectQueue(final long reconnectDelayMillis)

private Endpoint<E>
checkWithDefaultConnectorHandler(Endpoint<E> endpoint)

For backwards compatibility reasons (defaultConnectorHandler is deprecated in the builder), the method checks if the Endpoint is an EndpointKey, which doesn't provide a ConnectorHandler, in this case it sets the defaultConnectorHandler.

public void
close(final Endpoint<E>
Endpoint, that represents an endpoint
endpoint
)

Closes specific endpoint associated pool and releases its resources.

public void
close()

Closes the pool and releases associated resources.

protected SingleEndpointPool<E>
createSingleEndpointPool(Endpoint<E>
the endpoint key
endpoint
)

Creates SingleEndpointPool instance.

public boolean

Returns:

true if the Connection was detached, otherwise returns false
detach
(final Connection<L>
the Connection to detach
connection
)

Detaches a Connection from the pool.

public long
getAsyncPollTimeout(final TimeUnit timeUnit)

Returns: the timeout, after which, the async connection poll operation will fail with a timeout exception

public ConnectionInfo<E>

Returns:

pooled ConnectionInfo, that might be used for monitoring reasons, or null if the Connection does not belong to this pool
getConnectionInfo
(final Connection<L> connection)

Returns pooled ConnectionInfo, that might be used for monitoring reasons, or null if the Connection does not belong to this pool.

public long

Returns:

the maximum amount of time, a Connection could be associated with the pool
getConnectionTTL
(final TimeUnit timeUnit)

Return the maximum amount of time, a Connection could be associated with the pool.

public long
getConnectTimeout(final TimeUnit timeUnit)

Returns: the connection timeout, after which, if a connection is not established, it is considered failed

public long
getKeepAliveCheckInterval(final TimeUnit timeUnit)

Returns: the interval, which specifies how often the pool will perform idle Connections check

public long

Returns:

the maximum amount of time an idle Connection will be kept in the pool
getKeepAliveTimeout
(final TimeUnit timeUnit)

Returns the maximum amount of time an idle Connection will be kept in the pool.

public int
getMaxConnectionsPerEndpoint()

Returns: the maximum number of Connections each SingleEndpointPool sub-pool is allowed to have

public int
getMaxConnectionsTotal()

Returns: the total maximum number of Connections to be kept by the pool

public int
getMaxReconnectAttempts()

Returns: the maximum number of reconnect attempts

public int
getOpenConnectionsCount()

Returns: the number of connected Connections in the pool.

private MultiEndpointPool<E>.EndpointPoolImpl
public long
getReconnectDelay(final TimeUnit timeUnit)

Returns: the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous attempt fail

public boolean

Returns:

true only if the Connection is registered in the pool and is currently in busy state (used by a user), otherwise returns false
isBusy
(final Connection<L> 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.

public boolean
isFailFastWhenMaxSizeReached()

Returns: true, if the "take" method will fail fast if there is no free connection in the pool and max pool size is reached

public boolean
isMaxCapacityReached()

Returns: true is maximum number of Connections the pool can keep is reached and no new Connection can be established, or false otherwise.

public boolean

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
isRegistered
(final Connection<L> 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(final Endpoint<E>
Endpoint, that represents an endpoint
endpoint
)

Obtains SingleEndpointPool associated with the specific endpoint represented by Endpoint.

public Connection<L>
poll(final Endpoint<E>
Endpoint, that represents an endpoint
endpoint
)

Returns: a Connection from the pool, if there is one available at the moment, or null otherwise

public boolean

Returns:

true if the connection was successfully released. If the connection cannot be released, the connection will be closed and false will be returned.
release
(final Connection<L>
the Connection to return
connection
)

Returns the Connection to the pool.

public int
size()

Returns: the current pool size.

public GrizzlyFuture<Connection<L>>

Returns:

GrizzlyFuture
take
(final Endpoint<E>
Endpoint, that represents an endpoint
endpoint
)

Obtains a Connection to the specified endpoint from the pool in non-blocking/asynchronous fashion.

public void
take(final Endpoint<E>
Endpoint, that represents an endpoint
endpoint
,
final CompletionHandler<Connection<L>> completionHandler)

Obtains a Connection to the specified endpoint from the pool in non-blocking/asynchronous fashion.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait