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 class
AsyncPoolImpl.ShutdownException
static class
AsyncPoolImpl.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 CallTracker
createCallTracker()
void
dispose(T entity)
protected void
dispose0(T entity)
PoolStats
getPoolStats()
boolean
isShutdown()
Returns true if this resource has been shut down.boolean
isTerminated()
Returns true if the resource has completed shutting down.void
release(T entity)
protected void
release0(T entity)
void
shutdown()
Starts the shutdown process.java.util.concurrent.CompletableFuture<java.lang.Void>
shutdownPool()
int
size()
void
start()
protected CallCompletion
startWaiters()
void
waitForShutdown()
Waits for shutdown to completevoid
waitForShutdown(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:
isShutdown
in 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:
isTerminated
in 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:
shutdown
in interfaceShutdownable
-
shutdownPool
public java.util.concurrent.CompletableFuture<java.lang.Void> shutdownPool()
- Specified by:
shutdownPool
in interfaceAsyncPool<T>
-
waitForShutdown
public void waitForShutdown() throws java.lang.InterruptedException, java.lang.IllegalStateException
Waits for shutdown to complete- Specified by:
waitForShutdown
in 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.TimeoutException
Waits for shutdown to complete with a timeout- Specified by:
waitForShutdown
in 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:
getPoolStats
in interfaceAsyncPool<T>
-
-