Class SingleEndpointPool.Builder<E>
- java.lang.Object
-
- org.glassfish.grizzly.connectionpool.SingleEndpointPool.Builder<E>
-
- Type Parameters:
E- endpoint address type, for exampleSocketAddressfor TCP and UDP transports
- Direct Known Subclasses:
MultiEndpointPool.EndpointPoolBuilder
- Enclosing class:
- SingleEndpointPool<E>
public static class SingleEndpointPool.Builder<E> extends Object
The Builder class responsible for constructingSingleEndpointPool.
-
-
Field Summary
Fields Modifier and Type Field Description protected longasyncPollTimeoutMillisAsync poll timeout, after which, the async connection poll operation will be failed with a timeout exceptionprotected longconnectionTTLMillisthe maximum amount of time, aConnectioncould 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.protected org.glassfish.grizzly.ConnectorHandler<E>connectorHandlerConnectorHandlerused to establish newConnectionsprotected longconnectTimeoutMillisConnect timeout, after which, if a connection is not established, it is considered failedprotected intcorePoolSizeThe number ofConnections, kept in the pool, that are immune to keep-alive mechanismprotected org.glassfish.grizzly.utils.DelayedExecutordelayedExecutortheDelayedExecutorto be used for keep-alive and reconnect mechanismsprotected Endpoint<E>endpointThe endpoint informationprotected EendpointAddressEndpoint addressprotected booleanfailFastWhenMaxSizeReachedif true, the "take" method will fail fast if there is no free connection in the pool and max pool size is reached.protected longkeepAliveCheckIntervalMillisthe interval, which specifies how often the pool will perform idleConnections checkprotected longkeepAliveTimeoutMillisthe maximum number of milliseconds an idleConnectionwill be kept in the pool.protected ElocalEndpointAddressLocal bind address.protected intmaxPoolSizeThe max number ofConnections kept by this poolprotected intmaxReconnectAttemptsMaximum number of attempts that will be made to reconnect before notification of failure occurs.protected longreconnectDelayMillisthe delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect had failed
-
Constructor Summary
Constructors Modifier Constructor Description protectedBuilder()protectedBuilder(Endpoint<E> endpoint, org.glassfish.grizzly.ConnectorHandler<E> connectorHandler, E endpointAddress, E localEndpointAddress, int corePoolSize, int maxPoolSize, org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor, long connectTimeoutMillis, long reconnectDelayMillis, int maxReconnectAttempts, long asyncPollTimeoutMillis, long connectionTTLMillis, boolean failFastWhenMaxSizeReached, long keepAliveTimeoutMillis, long keepAliveCheckIntervalMillis)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SingleEndpointPool.Builder<E>asyncPollTimeout(long asyncPollTimeout, TimeUnit timeunit)Sets the max time consumer will wait for aConnectionto become available.SingleEndpointPool<E>build()ConstructsSingleEndpointPool.protected SingleEndpointPool<E>build0(Endpoint<E> e)SingleEndpointPool.Builder<E>connectionTTL(long connectionTTL, TimeUnit timeunit)Sets the max amount of time aConnectioncould be associated with the pool.SingleEndpointPool.Builder<E>connectorHandler(org.glassfish.grizzly.ConnectorHandler<E> connectorHandler)Sets theConnectorHandlerused to establish newConnections.SingleEndpointPool.Builder<E>connectTimeout(long connectTimeout, TimeUnit timeunit)Sets the max timeConnectionconnect operation may take.SingleEndpointPool.Builder<E>corePoolSize(int corePoolSize)Sets the number ofConnections, kept in the pool, that are immune to keep-alive mechanism.SingleEndpointPool.Builder<E>delayExecutor(org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor)Sets the customDelayedExecutorto be used for keep-alive and reconnect mechanisms.SingleEndpointPool.Builder<E>endpoint(Endpoint<E> endpoint)Sets the endpoint information.SingleEndpointPool.Builder<E>endpointAddress(E endpointAddress)Sets the endpoint address.SingleEndpointPool.Builder<E>failFastWhenMaxSizeReached(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.SingleEndpointPool.Builder<E>keepAliveCheckInterval(long keepAliveCheckInterval, TimeUnit timeunit)Sets the interval, which specifies how often the pool will perform idleConnections check.SingleEndpointPool.Builder<E>keepAliveTimeout(long keepAliveTimeout, TimeUnit timeunit)Sets the maximum number of milliseconds an idleConnectionwill be kept in the pool.SingleEndpointPool.Builder<E>localEndpointAddress(E localEndpointAddress)Sets the local endpoint address.SingleEndpointPool.Builder<E>maxPoolSize(int maxPoolSize)Sets the max number ofConnections kept by this pool.SingleEndpointPool.Builder<E>maxReconnectAttempts(int maxReconnectAttempts)If the reconnect mechanism is enabled, then this property will affect how many times a reconnection attempt can be made consecutively before a failure is flagged.SingleEndpointPool.Builder<E>reconnectDelay(long reconnectDelay, TimeUnit timeunit)Sets the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect operation had failed.
-
-
-
Field Detail
-
connectorHandler
protected org.glassfish.grizzly.ConnectorHandler<E> connectorHandler
ConnectorHandlerused to establish newConnections
-
endpointAddress
protected E endpointAddress
Endpoint address
-
localEndpointAddress
protected E localEndpointAddress
Local bind address.
-
corePoolSize
protected int corePoolSize
The number ofConnections, kept in the pool, that are immune to keep-alive mechanism
-
maxPoolSize
protected int maxPoolSize
The max number ofConnections kept by this pool
-
delayedExecutor
protected org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor
theDelayedExecutorto be used for keep-alive and reconnect mechanisms
-
connectTimeoutMillis
protected long connectTimeoutMillis
Connect timeout, after which, if a connection is not established, it is considered failed
-
reconnectDelayMillis
protected long reconnectDelayMillis
the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect had failed
-
maxReconnectAttempts
protected int maxReconnectAttempts
Maximum number of attempts that will be made to reconnect before notification of failure occurs.
-
asyncPollTimeoutMillis
protected long asyncPollTimeoutMillis
Async poll timeout, after which, the async connection poll operation will be failed with a timeout exception
-
connectionTTLMillis
protected long connectionTTLMillis
the maximum amount of time, aConnectioncould 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.
-
failFastWhenMaxSizeReached
protected 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.
-
keepAliveTimeoutMillis
protected long keepAliveTimeoutMillis
the maximum number of milliseconds an idleConnectionwill be kept in the pool. The idleConnections will be closed till the pool size is greater than corePoolSize
-
keepAliveCheckIntervalMillis
protected long keepAliveCheckIntervalMillis
the interval, which specifies how often the pool will perform idleConnections check
-
-
Constructor Detail
-
Builder
protected Builder()
-
Builder
protected Builder(Endpoint<E> endpoint, org.glassfish.grizzly.ConnectorHandler<E> connectorHandler, E endpointAddress, E localEndpointAddress, int corePoolSize, int maxPoolSize, org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor, long connectTimeoutMillis, long reconnectDelayMillis, int maxReconnectAttempts, long asyncPollTimeoutMillis, long connectionTTLMillis, boolean failFastWhenMaxSizeReached, long keepAliveTimeoutMillis, long keepAliveCheckIntervalMillis)
-
-
Method Detail
-
connectorHandler
public SingleEndpointPool.Builder<E> connectorHandler(org.glassfish.grizzly.ConnectorHandler<E> connectorHandler)
Sets theConnectorHandlerused to establish newConnections.- Parameters:
connectorHandler-ConnectorHandler- Returns:
- this
SingleEndpointPool.Builder
-
endpointAddress
public SingleEndpointPool.Builder<E> endpointAddress(E endpointAddress)
Sets the endpoint address.- Parameters:
endpointAddress-- Returns:
- this
SingleEndpointPool.Builder
-
localEndpointAddress
public SingleEndpointPool.Builder<E> localEndpointAddress(E localEndpointAddress)
Sets the local endpoint address.- Parameters:
localEndpointAddress-- Returns:
- this
SingleEndpointPool.Builder
-
endpoint
public SingleEndpointPool.Builder<E> endpoint(Endpoint<E> endpoint)
Sets the endpoint information. If set, this setting precedes theconnectorHandler(org.glassfish.grizzly.ConnectorHandler),endpointAddress(java.lang.Object)andlocalEndpointAddress(java.lang.Object)values, if they were or will be set.- Parameters:
endpoint-Endpoint- Returns:
- this
SingleEndpointPool.Builder
-
corePoolSize
public SingleEndpointPool.Builder<E> corePoolSize(int corePoolSize)
Sets the number ofConnections, kept in the pool, that are immune to keep-alive mechanism. Default value is 0.- Parameters:
corePoolSize-- Returns:
- this
SingleEndpointPool.Builder
-
maxPoolSize
public SingleEndpointPool.Builder<E> maxPoolSize(int maxPoolSize)
Sets the max number ofConnections kept by this pool. Default value is 4.- Parameters:
maxPoolSize-- Returns:
- this
SingleEndpointPool.Builder
-
delayExecutor
public SingleEndpointPool.Builder<E> delayExecutor(org.glassfish.grizzly.utils.DelayedExecutor delayedExecutor)
Sets the customDelayedExecutorto be used for keep-alive and reconnect mechanisms. If none is set - theSingleEndpointPoolwill create its ownDelayedExecutor.- Parameters:
delayedExecutor-- Returns:
- this
SingleEndpointPool.Builder
-
connectTimeout
public SingleEndpointPool.Builder<E> connectTimeout(long connectTimeout, TimeUnit timeunit)
Sets the max timeConnectionconnect operation may take. If timeout expires - the connect operation is considered failed. If connectTimeout < 0 - the connect timeout mechanism will be disabled. By default the connect timeout mechanism is disabled.- Parameters:
connectTimeout- the max timeConnectionconnect operation may take. If timeout expires - the connect operation is considered failed. The negative value disables the connect timeout mechanism.timeunit- a TimeUnit determining how to interpret the timeout parameter- Returns:
- this
SingleEndpointPool.Builder
-
reconnectDelay
public SingleEndpointPool.Builder<E> reconnectDelay(long reconnectDelay, TimeUnit timeunit)
Sets the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect operation had failed. If reconnectDelay < 0 - the reconnect mechanism will be disabled. By default the reconnect mechanism is disabled.- Parameters:
reconnectDelay- the delay to be used before the pool will repeat the attempt to connect to the endpoint after previous connect operation had failed. The negative value disables the reconnect mechanism.timeunit- a TimeUnit determining how to interpret the timeout parameter- Returns:
- this
SingleEndpointPool.Builder
-
maxReconnectAttempts
public SingleEndpointPool.Builder<E> maxReconnectAttempts(int maxReconnectAttempts)
If the reconnect mechanism is enabled, then this property will affect how many times a reconnection attempt can be made consecutively before a failure is flagged.- Parameters:
maxReconnectAttempts- the maximum number of reconnect attempts. If the reconnect mechanism isn't enabled, this property is ignored.- Returns:
- this
SingleEndpointPool.Builder
-
asyncPollTimeout
public SingleEndpointPool.Builder<E> asyncPollTimeout(long asyncPollTimeout, TimeUnit timeunit)
Sets the max time consumer will wait for aConnectionto become available. When timeout expires the consumer will be notified about the failure (TimeoutException) viaCompletionHandlerorFuture. If asyncPollTimeout < 0 - timeout will not be set. By default the timeout is not set and consumer may wait forever for aConnection.- Parameters:
asyncPollTimeout- the maximum time, the async poll operation could wait for a connection to become availabletimeunit- a TimeUnit determining how to interpret the timeout parameter- Returns:
- this
SingleEndpointPool.Builder
-
connectionTTL
public SingleEndpointPool.Builder<E> connectionTTL(long connectionTTL, TimeUnit timeunit)
Sets the max amount of time aConnectioncould be associated with the pool. Once timeout expired theConnectionwill be either closed, if it's idle, or detached from the pool, if it's being used. If connectionTTL < 0 - theConnectiontime to live will not be set and theConnectioncan be associated with a pool forever, if no other limit is hit (like keep-alive). By default the connectionTTL is not set.- Parameters:
connectionTTL- the max amount of time aConnectioncould be associated with the pooltimeunit- a TimeUnit determining how to interpret the connectionTTL parameter- Returns:
- this
SingleEndpointPool.Builder
-
failFastWhenMaxSizeReached
public SingleEndpointPool.Builder<E> failFastWhenMaxSizeReached(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. Otherwise the pool will queue up the take request and wait for aConnectionto become available- Parameters:
failFastWhenMaxSizeReached-- Returns:
- this
SingleEndpointPool.Builder
-
keepAliveTimeout
public SingleEndpointPool.Builder<E> keepAliveTimeout(long keepAliveTimeout, TimeUnit timeunit)
Sets the maximum number of milliseconds an idleConnectionwill be kept in the pool. The idleConnections will be closed till the pool size is greater than corePoolSize. If keepAliveTimeout < 0 - the keep-alive mechanism will be disabled. By default the keep-alive timeout is set to 30 seconds.- Parameters:
keepAliveTimeout- the maximum number of milliseconds an idleConnectionwill be kept in the pool. The negative value disables the keep-alive mechanism.timeunit- a TimeUnit determining how to interpret the timeout parameter- Returns:
- this
SingleEndpointPool.Builder
-
keepAliveCheckInterval
public SingleEndpointPool.Builder<E> keepAliveCheckInterval(long keepAliveCheckInterval, TimeUnit timeunit)
Sets the interval, which specifies how often the pool will perform idleConnections check.- Parameters:
keepAliveCheckInterval- the interval, which specifies how often the pool will perform idleConnections checktimeunit- a TimeUnit determining how to interpret the timeout parameter- Returns:
- this
SingleEndpointPool.Builder
-
build
public SingleEndpointPool<E> build()
ConstructsSingleEndpointPool.- Returns:
SingleEndpointPool
-
build0
protected SingleEndpointPool<E> build0(Endpoint<E> e)
-
-