Top Description Inners Fields Constructors Methods
org.apache.hc.core5.pool

public Class StrictConnPool<T, C extends org.apache.hc.core5.io.ModalCloseable>

extends Object
implements ManagedConnPool<T, C extends ModalCloseable>
Class Inheritance
All Implemented Interfaces
org.apache.hc.core5.pool.ManagedConnPool, org.apache.hc.core5.io.ModalCloseable, java.io.Closeable, java.lang.AutoCloseable, org.apache.hc.core5.pool.ConnPoolControl, org.apache.hc.core5.pool.ConnPoolStats, org.apache.hc.core5.pool.ConnPool
Annotations
@Contract
threading:SAFE
Type Parameters
<T>
route
<C>
connection object
Imports
java.util.HashMap, .HashSet, .Iterator, .LinkedList, .ListIterator, .Map, .Objects, .Set, java.util.concurrent.ConcurrentLinkedQueue, .ExecutionException, .Future, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicBoolean, java.util.concurrent.locks.Lock, .ReentrantLock, org.apache.hc.core5.annotation.Contract, .ThreadingBehavior, org.apache.hc.core5.concurrent.BasicFuture, .FutureCallback, org.apache.hc.core5.function.Callback, org.apache.hc.core5.io.CloseMode, .ModalCloseable, org.apache.hc.core5.util.Args, .Asserts, .Deadline, .DeadlineTimeoutException, .TimeValue, .Timeout

Connection pool with strict connection limit guarantees.
Since
4.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final LinkedList<PoolEntry<T, C>>
private final ConcurrentLinkedQueue<StrictConnPool.LeaseRequest<T, C>>
private final ConnPoolListener<T>
private volatile int
private final DisposalCallback<C>
private final AtomicBoolean
private final Set<PoolEntry<T, C>>
private final Lock
private final Map<T, Integer>
private volatile int
private final LinkedList<StrictConnPool.LeaseRequest<T, C>>
private final PoolReusePolicy
private final Map<T, StrictConnPool.PerRoutePool<T, C>>
private final TimeValue

Constructor Summary

AccessConstructor and Description
public
StrictConnPool(final int defaultMaxPerRoute, final int maxTotal, final TimeValue timeToLive, final PoolReusePolicy policy, final DisposalCallback<C> disposalCallback, final ConnPoolListener<T> connPoolListener)

public
StrictConnPool(final int defaultMaxPerRoute, final int maxTotal, final TimeValue timeToLive, final PoolReusePolicy policy, final ConnPoolListener<T> connPoolListener)

public
StrictConnPool(final int defaultMaxPerRoute, final int maxTotal)

Method Summary

Modifier and TypeMethod and Description
public void
close(final CloseMode
How to close the receiver.
closeMode
)

Implements org.apache.hc.core5.io.ModalCloseable.close.

Closes this process or endpoint and releases any system resources associated with it.
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public void
public void
public void
enumAvailable(final Callback<PoolEntry<T, C>> callback)

Enumerates all available connections.

public void
enumLeased(final Callback<PoolEntry<T, C>> callback)

Enumerates all leased connections.

private void
public int
private int
getMax(final T route)

public int
public int
private StrictConnPool.PerRoutePool<T, C>
getPool(final T route)

public Set<T>
getRoutes()

Implements org.apache.hc.core5.pool.ConnPoolControl.getRoutes.

Returns snapshot of all knows routes
public PoolStats
public PoolStats
public boolean
public Future<PoolEntry<T, C>>
lease(final T
route of the connection.
route
,
final Object
arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.
state
,
final Timeout
request timeout. In case of a timeout the request can get automatically cancelled by the pool.
requestTimeout
,
final FutureCallback<PoolEntry<T, C>>
operation completion callback.
callback
)

Implements org.apache.hc.core5.pool.ConnPool.lease.

Attempts to lease a connection for the given route and with the given state from the pool.
public Future<PoolEntry<T, C>>
lease(final T route, final Object state)

private void
private boolean
private void
private void
public void
release(final PoolEntry<T, C>
pool entry leased from the pool
entry
,
final boolean
flag indicating whether or not the released connection is in a consistent state and is safe for further use.
reusable
)

Implements org.apache.hc.core5.pool.ConnPool.release.

Releases the pool entry back to the pool.
public void
public void
public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

availableback to summary
private final LinkedList<PoolEntry<T, C>> available
completedRequestsback to summary
private final ConcurrentLinkedQueue<StrictConnPool.LeaseRequest<T, C>> completedRequests
connPoolListenerback to summary
private final ConnPoolListener<T> connPoolListener
defaultMaxPerRouteback to summary
private volatile int defaultMaxPerRoute
disposalCallbackback to summary
private final DisposalCallback<C> disposalCallback
isShutDownback to summary
private final AtomicBoolean isShutDown
leasedback to summary
private final Set<PoolEntry<T, C>> leased
lockback to summary
private final Lock lock
maxPerRouteback to summary
private final Map<T, Integer> maxPerRoute
maxTotalback to summary
private volatile int maxTotal
pendingRequestsback to summary
private final LinkedList<StrictConnPool.LeaseRequest<T, C>> pendingRequests
policyback to summary
private final PoolReusePolicy policy
routeToPoolback to summary
private final Map<T, StrictConnPool.PerRoutePool<T, C>> routeToPool
timeToLiveback to summary
private final TimeValue timeToLive

Constructor Detail

StrictConnPoolback to summary
public StrictConnPool(final int defaultMaxPerRoute, final int maxTotal, final TimeValue timeToLive, final PoolReusePolicy policy, final DisposalCallback<C> disposalCallback, final ConnPoolListener<T> connPoolListener)
Since
5.0
StrictConnPoolback to summary
public StrictConnPool(final int defaultMaxPerRoute, final int maxTotal, final TimeValue timeToLive, final PoolReusePolicy policy, final ConnPoolListener<T> connPoolListener)
Since
5.0
StrictConnPoolback to summary
public StrictConnPool(final int defaultMaxPerRoute, final int maxTotal)

Method Detail

closeback to summary
public void close(final CloseMode closeMode)

Implements org.apache.hc.core5.io.ModalCloseable.close.

Doc from org.apache.hc.core5.io.ModalCloseable.close.

Closes this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.

Parameters
closeMode:CloseMode

How to close the receiver.

Annotations
@Override
closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
closeExpiredback to summary
public void closeExpired()

Implements org.apache.hc.core5.pool.ConnPoolControl.closeExpired.

Annotations
@Override
closeIdleback to summary
public void closeIdle(final TimeValue idleTime)

Implements org.apache.hc.core5.pool.ConnPoolControl.closeIdle.

Annotations
@Override
enumAvailableback to summary
public void enumAvailable(final Callback<PoolEntry<T, C>> callback)

Enumerates all available connections.

Since
4.3
enumLeasedback to summary
public void enumLeased(final Callback<PoolEntry<T, C>> callback)

Enumerates all leased connections.

Since
4.3
fireCallbacksback to summary
private void fireCallbacks()
getDefaultMaxPerRouteback to summary
public int getDefaultMaxPerRoute()

Implements org.apache.hc.core5.pool.ConnPoolControl.getDefaultMaxPerRoute.

Annotations
@Override
getMaxback to summary
private int getMax(final T route)
getMaxPerRouteback to summary
public int getMaxPerRoute(final T route)

Implements org.apache.hc.core5.pool.ConnPoolControl.getMaxPerRoute.

Annotations
@Override
getMaxTotalback to summary
public int getMaxTotal()

Implements org.apache.hc.core5.pool.ConnPoolControl.getMaxTotal.

Annotations
@Override
getPoolback to summary
private StrictConnPool.PerRoutePool<T, C> getPool(final T route)
getRoutesback to summary
public Set<T> getRoutes()

Implements org.apache.hc.core5.pool.ConnPoolControl.getRoutes.

Returns snapshot of all knows routes

Annotations
@Override
Since
4.4
getStatsback to summary
public PoolStats getStats(final T route)

Implements org.apache.hc.core5.pool.ConnPoolStats.getStats.

Annotations
@Override
getTotalStatsback to summary
public PoolStats getTotalStats()

Implements org.apache.hc.core5.pool.ConnPoolStats.getTotalStats.

Annotations
@Override
isShutdownback to summary
public boolean isShutdown()
leaseback to summary
public Future<PoolEntry<T, C>> lease(final T route, final Object state, final Timeout requestTimeout, final FutureCallback<PoolEntry<T, C>> callback)

Implements org.apache.hc.core5.pool.ConnPool.lease.

Doc from org.apache.hc.core5.pool.ConnPool.lease.

Attempts to lease a connection for the given route and with the given state from the pool.

Please note the connection request can get automatically cancelled by the pool in case of a request timeout.

Parameters
route:T

route of the connection.

state:Object

arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.

requestTimeout:Timeout

request timeout. In case of a timeout the request can get automatically cancelled by the pool.

callback:FutureCallback<PoolEntry<T, C>>

operation completion callback.

Returns:Future<PoolEntry<T, C>>

future for a leased pool entry.

Annotations
@Override
leaseback to summary
public Future<PoolEntry<T, C>> lease(final T route, final Object state)
processNextPendingRequestback to summary
private void processNextPendingRequest()
processPendingRequestback to summary
private boolean processPendingRequest(final StrictConnPool.LeaseRequest<T, C> request)
processPendingRequestsback to summary
private void processPendingRequests()
purgePoolMapback to summary
private void purgePoolMap()
releaseback to summary
public void release(final PoolEntry<T, C> entry, final boolean reusable)

Implements org.apache.hc.core5.pool.ConnPool.release.

Doc from org.apache.hc.core5.pool.ConnPool.release.

Releases the pool entry back to the pool.

Parameters
entry:PoolEntry<T, C>

pool entry leased from the pool

reusable:boolean

flag indicating whether or not the released connection is in a consistent state and is safe for further use.

Annotations
@Override
setDefaultMaxPerRouteback to summary
public void setDefaultMaxPerRoute(final int max)

Implements org.apache.hc.core5.pool.ConnPoolControl.setDefaultMaxPerRoute.

Annotations
@Override
setMaxPerRouteback to summary
public void setMaxPerRoute(final T route, final int max)

Implements org.apache.hc.core5.pool.ConnPoolControl.setMaxPerRoute.

Annotations
@Override
setMaxTotalback to summary
public void setMaxTotal(final int max)

Implements org.apache.hc.core5.pool.ConnPoolControl.setMaxTotal.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
validatePendingRequestsback to summary
public void validatePendingRequests()
org.apache.hc.core5.pool back to summary

pack-priv Class StrictConnPool.LeaseRequest<T, C extends org.apache.hc.core5.io.ModalCloseable>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private final Deadline
private volatile Exception
private final BasicFuture<PoolEntry<T, C>>
private volatile PoolEntry<T, C>
private final T
private final Object

Constructor Summary

AccessConstructor and Description
public
LeaseRequest(final T
route
route
,
final Object
state
state
,
final Timeout
timeout to wait in a request queue until kicked off
requestTimeout
,
final BasicFuture<PoolEntry<T, C>>
future callback
future
)

Constructor

Method Summary

Modifier and TypeMethod and Description
public void
completed(final PoolEntry<T, C> result)

public void
failed(final Exception ex)

public Deadline
public Exception
public BasicFuture<PoolEntry<T, C>>
public PoolEntry<T, C>
public T
public Object
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

completedback to summary
private final AtomicBoolean completed
deadlineback to summary
private final Deadline deadline
exback to summary
private volatile Exception ex
futureback to summary
private final BasicFuture<PoolEntry<T, C>> future
resultback to summary
private volatile PoolEntry<T, C> result
routeback to summary
private final T route
stateback to summary
private final Object state

Constructor Detail

LeaseRequestback to summary
public LeaseRequest(final T route, final Object state, final Timeout requestTimeout, final BasicFuture<PoolEntry<T, C>> future)

Constructor

Parameters
route:T

route

state:Object

state

requestTimeout:Timeout

timeout to wait in a request queue until kicked off

future:BasicFuture<PoolEntry<T, C>>

future callback

Method Detail

completedback to summary
public void completed(final PoolEntry<T, C> result)
failedback to summary
public void failed(final Exception ex)
getDeadlineback to summary
public Deadline getDeadline()
getExceptionback to summary
public Exception getException()
getFutureback to summary
public BasicFuture<PoolEntry<T, C>> getFuture()
getResultback to summary
public PoolEntry<T, C> getResult()
getRouteback to summary
public T getRoute()
getStateback to summary
public Object getState()
isDoneback to summary
public boolean isDone()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.apache.hc.core5.pool back to summary

pack-priv Class StrictConnPool.PerRoutePool<T, C extends org.apache.hc.core5.io.ModalCloseable>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final LinkedList<PoolEntry<T, C>>
private final DisposalCallback<C>
private final Set<PoolEntry<T, C>>
private final T

Constructor Summary

AccessConstructor and Description
pack-priv
PerRoutePool(final T route, final DisposalCallback<C> disposalCallback)

Method Summary

Modifier and TypeMethod and Description
public PoolEntry<T, C>
createEntry(final TimeValue timeToLive)

public void
free(final PoolEntry<T, C> entry, final boolean reusable)

public int
public int
public PoolEntry<T, C>
getFree(final Object state)

public PoolEntry<T, C>
public int
public final T
public boolean
remove(final PoolEntry<T, C> entry)

public void
shutdown(final CloseMode closeMode)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

availableback to summary
private final LinkedList<PoolEntry<T, C>> available
disposalCallbackback to summary
private final DisposalCallback<C> disposalCallback
leasedback to summary
private final Set<PoolEntry<T, C>> leased
routeback to summary
private final T route

Constructor Detail

PerRoutePoolback to summary
pack-priv PerRoutePool(final T route, final DisposalCallback<C> disposalCallback)

Method Detail

createEntryback to summary
public PoolEntry<T, C> createEntry(final TimeValue timeToLive)
freeback to summary
public void free(final PoolEntry<T, C> entry, final boolean reusable)
getAllocatedCountback to summary
public int getAllocatedCount()
getAvailableCountback to summary
public int getAvailableCount()
getFreeback to summary
public PoolEntry<T, C> getFree(final Object state)
getLastUsedback to summary
public PoolEntry<T, C> getLastUsed()
getLeasedCountback to summary
public int getLeasedCount()
getRouteback to summary
public final T getRoute()
removeback to summary
public boolean remove(final PoolEntry<T, C> entry)
shutdownback to summary
public void shutdown(final CloseMode closeMode)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override