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

public Class SingleEndpointPool<E>

extends Object
Class Inheritance
Known Direct Subclasses
org.glassfish.grizzly.connectionpool.MultiEndpointPool.EndpointPoolImpl
Type Parameters
<E>
the address type, for example for TCP transport it's SocketAddress
Imports
java.io.IOException, java.net.ConnectException, .SocketAddress, java.util.HashMap, .Map, java.util.concurrent.ExecutorService, .Future, .TimeUnit, .TimeoutException, java.util.logging.Level, .Logger, org.glassfish.grizzly.CloseListener, .CloseType, .CompletionHandler, .Connection, .ConnectorHandler, .EmptyCompletionHandler, .Grizzly, .GrizzlyFuture, org.glassfish.grizzly.impl.FutureImpl, .SafeFutureImpl, org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler, .UDPNIOConnectorHandler, org.glassfish.grizzly.threadpool.GrizzlyExecutorService, .ThreadPoolConfig, org.glassfish.grizzly.utils.DelayedExecutor, .DelayedExecutor.DelayQueue, .Futures

The single endpoint Connection pool implementation, in other words this pool manages Connections to one specific endpoint. The endpoint address has to be represented by an objected understandable by a ConnectorHandler passed to the constructor. For example the endpoint address has to be represented by SocketAddress for TCPNIOConnectorHandler and UDPNIOConnectorHandler. There are number of configuration options supported by the SingleEndpointPool: - corePoolSize: the number of Connections to be kept in the pool and never timed out because of keep-alive setting; - maxPoolSize: the 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 till the pool size is greater than 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
protected static class
pack-priv static class
pack-priv static class
SingleEndpointPool.AsyncPollTimeoutWorker

Async poll timeout mechanism classes related to DelayedExecutor.

public static class
SingleEndpointPool.Builder<
endpoint address type, for example SocketAddress for TCP and UDP transports
E
>

The Builder class responsible for constructing SingleEndpointPool.

private class
SingleEndpointPool.ConnectCompletionHandler

CompletionHandler to be notified once new Connection is connected or failed to connect.

protected static class
protected static class
SingleEndpointPool.ConnectionTTLWorker

Connect timeout mechanism classes related to DelayedExecutor.

protected static class
protected static class
protected static class
SingleEndpointPool.ConnectTimeoutWorker

Connect timeout mechanism classes related to DelayedExecutor.

protected static class
SingleEndpointPool.KeepAliveCleaner

Keep-alive mechanism classes related to DelayedExecutor.

protected static class
protected static class
private class
SingleEndpointPool.PoolConnectionCloseListener

The CloseListener to be notified, when pool Connection either busy or ready has been closed, so the pool can adjust its counters.

protected static class
SingleEndpointPool.Reconnector

Reconnect mechanism classes related to DelayedExecutor.

protected static class
protected static class

Field Summary

Modifier and TypeField and Description
private final long
asyncPollTimeoutMillis

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

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

DelayQueue for async poll timeout mechanism

private final Chain<SingleEndpointPool.AsyncPoll>
asyncWaitingList

The waiting list of asynchronous polling clients

private final SingleEndpointPool<E>.PoolConnectionCloseListener
closeListener

CloseListener to be notified once pooled Connection is closed

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

The Map contains *all* pooled Connections

private final long
connectionTTLMillis

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

private final 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 final DelayedExecutor.DelayQueue<SingleEndpointPool.ConnectTimeoutTask>
connectTimeoutQueue

DelayQueue for connect timeout mechanism

private final int
corePoolSize

The number of Connections, kept in the pool, that are immune to keep-alive mechanism

private final SingleEndpointPool<E>.ConnectCompletionHandler
private final Endpoint<E>
endpoint

The endpoint description

private int
failedConnectAttempts

Number of failed connect attempts.

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 final 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
protected final int
maxPoolSize

The max number of Connections kept by this pool

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

protected int
pendingConnections

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

private int
poolSize

current pool size

pack-priv final Object
poolSync

Sync object

private final Chain<ConnectionInfo<E>>
readyConnections

The Chain of ready connections

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 final DelayedExecutor.DelayQueue<SingleEndpointPool.ReconnectTask<E>>
reconnectQueue

DelayQueue for reconnect mechanism

Constructor Summary

AccessConstructor and Description
protected
SingleEndpointPool(final Endpoint<E>
Endpoint to be used to establish new Connections
endpoint
,
final int
the number of Connections, kept in the pool, that are immune to keep-alive mechanism
corePoolSize
,
final int
the max number of Connections kept by this pool
maxPoolSize
,
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
)

Constructs SingleEndpointPool instance.

protected
SingleEndpointPool(final Endpoint<E>
Endpoint to be used to establish new Connections
endpoint
,
final int
the number of Connections, kept in the pool, that are immune to keep-alive mechanism
corePoolSize
,
final int
the max number of Connections kept by this pool
maxPoolSize
,
final DelayedExecutor.DelayQueue<SingleEndpointPool.ConnectTimeoutTask>
the DelayQueue used by connect timeout mechanism
connectTimeoutQueue
,
final DelayedExecutor.DelayQueue<SingleEndpointPool.ReconnectTask<E>>
the DelayQueue used by reconnect mechanism
reconnectQueue
,
final DelayedExecutor.DelayQueue<SingleEndpointPool.KeepAliveCleanerTask<E>>
the DelayQueue used by keep-alive mechanism
keepAliveCleanerQueue
,
final DelayedExecutor.DelayQueue<Link<SingleEndpointPool.AsyncPoll>>
the DelayQueue used by async connection poll mechanism
asyncPollTimeoutQueue
,
final DelayedExecutor.DelayQueue<ConnectionInfo<E>>
the DelayQueue used by connection TTL mechanism
connectionTTLQueue
,
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
)

Constructs SingleEndpointPool 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 Connection<L> connection)

Attaches "foreign" Connection to the pool.

pack-priv ConnectionInfo<E>
attach0(final Connection<L> connection)

The method attaches Connection to the pool.

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

Returns:

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

Returns single endpoint pool Builder.

protected boolean

Returns:

true if new connection could be created, or false otherwise
checkBeforeOpeningConnection
()

The method is called before the pool will try to establish new client connection.

pack-priv boolean
cleanupIdleConnections(final SingleEndpointPool.KeepAliveCleanerTask<E> cleanerTask)

Perform keep-alive check on the ready connections and close connections, that keep-alive timeout has been expired.

public void
close()

Closes the pool and release associated resources.

private void
connect()

Establish new pool connection.

protected boolean

Returns:

true if a new Connection could be open, or false otherwise
createConnectionIfPossible
()

Checks if it's possible to create a new Connection by calling checkBeforeOpeningConnection() and if it is possible - establish new connection.

private boolean

Returns:

true if a new Connection could be open, or false otherwise
createConnectionIfPossibleNoSync
()

Checks if it's possible to create a new Connection by calling checkBeforeOpeningConnection() and if it is possible - establish new connection.

private void
public boolean

Returns:

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

Detaches a Connection from the pool.

private SingleEndpointPool.AsyncPoll
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 int
getCorePoolSize()

Returns: the number of Connections, kept in the pool, that are immune to keep-alive mechanism

public Endpoint<E>
getEndpoint()

Returns: the endpoint description

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
getMaxPoolSize()

Returns: the max number of Connections kept by this pool

public int
getMaxReconnectAttempts()

Returns: the maximum number of reconnect attempts

public int
getOpenConnectionsCount()

Returns: the number of connected Connections in the pool.

public int
getReadyConnectionsCount()

Returns: the number of Connections ready to be retrieved and used.

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

protected int
getWaitingListSize()

Returns: the number of consumers waiting for a connection

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.

pack-priv boolean
isBusy0(final ConnectionInfo<E> connectionRecord)

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.

pack-priv boolean
isOverflown()

Returns: true if number of live connections is more or equal to max pool size

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.

private void
private SingleEndpointPool.AsyncPoll
pack-priv void
onCloseConnection(final ConnectionInfo<E> info)

The method will be called to notify about connection termination.

pack-priv void
onConnected(final Connection<L> connection)

The method will be called to notify about newly open connection (not attached yet)

pack-priv void
onFailedConnection()

The method will be called to notify about error occurred during new connection opening.

public Connection<L>
poll()

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.

pack-priv boolean
release0(final ConnectionInfo<E> info)

Same as release(org.glassfish.grizzly.Connection), but is based on connection Link.

public int

Returns:

the current pool size
size
()

Returns the current pool size.

public GrizzlyFuture<Connection<L>>

Returns:

GrizzlyFuture
take
()

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

public void
take(final CompletionHandler<Connection<L>>
to be notified once Connection is available or an error occurred
completionHandler
)

Obtains a Connection 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