Class AsyncPoolImpl<T>
- java.lang.Object
-
- com.linkedin.alpini.base.pool.impl.AsyncPoolImpl<T>
-
- All Implemented Interfaces:
AsyncPool<T>,Shutdownable,ShutdownableResource
- Direct Known Subclasses:
AsyncQOSPoolImpl
public class AsyncPoolImpl<T> extends java.lang.Object implements AsyncPool<T>, ShutdownableResource
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAsyncPoolImpl.ShutdownExceptionstatic classAsyncPoolImpl.TooManyWaitersException-
Nested classes/interfaces inherited from interface com.linkedin.alpini.base.pool.AsyncPool
AsyncPool.LifeCycle<T>
-
-
Constructor Summary
Constructors Constructor Description AsyncPoolImpl(AsyncPool.LifeCycle<T> lifeCycle, java.util.concurrent.Executor executor, int maxConcurrentCreate, int maxWaiters, int minimumEntities, int maximumEntities, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleUnit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<T>acquire()protected java.util.concurrent.CompletableFuture<T>acquire0()protected java.util.concurrent.CompletableFuture<T>checkout(java.util.concurrent.CompletableFuture<T> future, CallCompletion waiter)protected CallTrackercreateCallTracker()voiddispose(T entity)protected voiddispose0(T entity)PoolStatsgetPoolStats()booleanisShutdown()Returns true if this resource has been shut down.booleanisTerminated()Returns true if the resource has completed shutting down.voidrelease(T entity)protected voidrelease0(T entity)voidshutdown()Starts the shutdown process.java.util.concurrent.CompletableFuture<java.lang.Void>shutdownPool()intsize()voidstart()protected CallCompletionstartWaiters()voidwaitForShutdown()Waits for shutdown to completevoidwaitForShutdown(long timeoutInMs)Waits for shutdown to complete with a timeout
-
-
-
Constructor Detail
-
AsyncPoolImpl
public AsyncPoolImpl(AsyncPool.LifeCycle<T> lifeCycle, java.util.concurrent.Executor executor, int maxConcurrentCreate, int maxWaiters, int minimumEntities, int maximumEntities, long maxIdleTime, java.util.concurrent.TimeUnit maxIdleUnit)
-
-
Method Detail
-
createCallTracker
protected CallTracker createCallTracker()
-
startWaiters
protected final CallCompletion startWaiters()
-
checkout
protected java.util.concurrent.CompletableFuture<T> checkout(@Nonnull java.util.concurrent.CompletableFuture<T> future, @Nonnull CallCompletion waiter)
-
acquire
public java.util.concurrent.CompletableFuture<T> acquire()
-
acquire0
protected final java.util.concurrent.CompletableFuture<T> acquire0()
-
release0
protected final void release0(T entity)
-
dispose0
protected final void dispose0(T entity)
-
isShutdown
public boolean isShutdown()
Returns true if this resource has been shut down.- Specified by:
isShutdownin interfaceShutdownableResource- Returns:
- true if this resource has been shut down
-
isTerminated
public boolean isTerminated()
Returns true if the resource has completed shutting down. Note that isTerminated is never true unless shutdown was called first.- Specified by:
isTerminatedin interfaceShutdownableResource- Returns:
- true if the resource has completed shutting down.
-
shutdown
public void shutdown()
Starts the shutdown process. It is recommended to perform the actual shutdown activity in a separate thread from the thread that calls shutdown- Specified by:
shutdownin interfaceShutdownable
-
shutdownPool
public java.util.concurrent.CompletableFuture<java.lang.Void> shutdownPool()
- Specified by:
shutdownPoolin interfaceAsyncPool<T>
-
waitForShutdown
public void waitForShutdown() throws java.lang.InterruptedException, java.lang.IllegalStateExceptionWaits for shutdown to complete- Specified by:
waitForShutdownin interfaceShutdownable- Throws:
java.lang.InterruptedException- when the wait is interruptedjava.lang.IllegalStateException- when the method is invoked when the shutdown has yet to be started
-
waitForShutdown
public void waitForShutdown(long timeoutInMs) throws java.lang.InterruptedException, java.lang.IllegalStateException, java.util.concurrent.TimeoutExceptionWaits for shutdown to complete with a timeout- Specified by:
waitForShutdownin interfaceShutdownable- Parameters:
timeoutInMs- number of milliseconds to wait before throwing TimeoutException- Throws:
java.lang.InterruptedException- when the wait is interruptedjava.lang.IllegalStateException- when the method is invoked when the shutdown has yet to be startedjava.util.concurrent.TimeoutException- when the operation times out
-
getPoolStats
public PoolStats getPoolStats()
- Specified by:
getPoolStatsin interfaceAsyncPool<T>
-
-