Package org.apache.tomcat.jdbc.pool
Class FairBlockingQueue.ItemFuture<T>
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.FairBlockingQueue.ItemFuture<T>
-
- Type Parameters:
T- the type of the item
- All Implemented Interfaces:
java.util.concurrent.Future<T>
- Enclosing class:
- FairBlockingQueue<E>
protected class FairBlockingQueue.ItemFuture<T> extends java.lang.Object implements java.util.concurrent.Future<T>A future used to check if a connection has been made available. Cancelling the future deregisters its waiter from the queue, as long as the item has not already been handed over to the future.
Aget(long, TimeUnit)call that times out deregisters the waiter in the same way, and additionally fails the future terminally: no offer can reach the deregistered latch anymore, so the future reportsisDone()true without ever being cancelled, keeps failing every laterget(long, TimeUnit)with aTimeoutExceptionand every laterget()with anExecutionExceptioncaused by one, and can no longer be cancelled.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanabandonedWhether aget(long, TimeUnit)call on this future timed out.protected booleancanceledWhether this future has been cancelled.protected TitemThe item directly available in the future.protected FairBlockingQueue.ExchangeCountDownLatch<T>latchThe latch used to wait for an item.
-
Constructor Summary
Constructors Constructor Description ItemFuture(FairBlockingQueue.ExchangeCountDownLatch<T> latch)Creates an ItemFuture that waits on the given latch.ItemFuture(T item)Creates an ItemFuture with the given item already available.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)Tget()Tget(long timeout, java.util.concurrent.TimeUnit unit)booleanisCancelled()booleanisDone()
-
-
-
Field Detail
-
item
protected volatile T item
The item directly available in the future.
-
latch
protected volatile FairBlockingQueue.ExchangeCountDownLatch<T> latch
The latch used to wait for an item.
-
canceled
protected volatile boolean canceled
Whether this future has been cancelled.
-
abandoned
protected volatile boolean abandoned
Whether aget(long, TimeUnit)call on this future timed out. Its waiter was then deregistered from the queue, so no item can ever be handed over to this future anymore; the future is terminally failed and its get() methods fail fast instead of parking on a latch that nothing can count down again.
-
-
Constructor Detail
-
ItemFuture
public ItemFuture(T item)
Creates an ItemFuture with the given item already available.- Parameters:
item- the item
-
ItemFuture
public ItemFuture(FairBlockingQueue.ExchangeCountDownLatch<T> latch)
Creates an ItemFuture that waits on the given latch.- Parameters:
latch- the latch to wait on
-
-
Method Detail
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancelin interfacejava.util.concurrent.Future<T>
-
get
public T get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
getin interfacejava.util.concurrent.Future<T>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
get
public T get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
getin interfacejava.util.concurrent.Future<T>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfacejava.util.concurrent.Future<T>
-
isDone
public boolean isDone()
- Specified by:
isDonein interfacejava.util.concurrent.Future<T>
-
-