T - The type of the object to be returned.public abstract class FutureSynchronizer<T> extends AbstractQueuedSynchronizer
Future implementation.
This class implements the shared lock using
AbstractQueuedSynchronizer.
The shared lock is unavailable until the task completes.
AbstractQueuedSynchronizer.ConditionObject| Modifier and Type | Field and Description |
|---|---|
protected static int |
LOCK_ARG
An integer value to be passed to shared lock methods.
|
protected static int |
LOCK_FAILED
An integer value that indicates the shared lock is unavailable.
|
protected static int |
LOCK_SUCCEEDED
An integer value that indicates the shared lock is available for
shared lock.
|
protected static long |
serialVersionUID
Version number for serialization.
|
protected static int |
STATE_CANCELED
Internal state that indicates the task has been canceled.
|
protected static int |
STATE_COMPLETED
Internal state that indicates the task has completed.
|
protected static int |
STATE_COMPLETING
Internal state that indicates the task is going to complete.
|
protected static int |
STATE_EXECUTING
Internal state that indicates the task associated with the future is
executing.
|
| Modifier | Constructor and Description |
|---|---|
protected |
FutureSynchronizer()
Construct a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
awaitCompletion(int state)
Await completion of the task only if the task is about to complete.
|
protected static CancellationException |
canceled()
Return a
CancellationException that indicates the task was
canceled. |
boolean |
done(int expected,
int state,
T result,
Throwable cause)
Complete the future.
|
T |
get()
Wait for the task to complete, and then return the result of the task.
|
T |
get(long nano)
Wait for the task to complete, and then return the result of the task.
|
T |
getResult()
Return the result of the task.
|
Throwable |
getTaskCause()
Return a
Throwable that indicates the cause of failure. |
protected static InterruptedException |
interrupted()
Return an
InterruptedException that indicates the task was
interrupted. |
void |
interruptTask()
Interrupt the task executing the task.
|
boolean |
isCancelled()
Determine whether the task was canceled before it completed normally.
|
boolean |
isDone()
Determine whether the task completed or not.
|
void |
setResult(T result,
Throwable cause)
Set the result of the task.
|
boolean |
setThread(Thread t)
Set a thread that is executing the task.
|
protected int |
tryAcquireShared(int arg)
Attempts to acquire the shared lock.
|
protected boolean |
tryReleaseShared(int state)
Attempts to release the shared lock.
|
protected static IllegalStateException |
unexpectedState(int state)
Return an
IllegalStateException that indicates the current
future is in unexpected state. |
acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, isHeldExclusively, isQueued, owns, release, releaseShared, setState, toString, tryAcquire, tryAcquireNanos, tryAcquireSharedNanos, tryReleasegetExclusiveOwnerThread, setExclusiveOwnerThreadprotected static final long serialVersionUID
protected static final int STATE_EXECUTING
protected static final int STATE_COMPLETING
protected static final int STATE_COMPLETED
protected static final int STATE_CANCELED
protected static final int LOCK_ARG
protected static final int LOCK_SUCCEEDED
protected static final int LOCK_FAILED
protected static final InterruptedException interrupted()
InterruptedException that indicates the task was
interrupted.InterruptedException instance.protected static final CancellationException canceled()
CancellationException that indicates the task was
canceled.CancellationException instance.protected static final IllegalStateException unexpectedState(int state)
IllegalStateException that indicates the current
future is in unexpected state.state - The current internal state value.IllegalStateException instance.public final boolean setThread(Thread t)
t - A Thread instance.true only if the task has already been canceled.public final boolean isCancelled()
true only if the task was canceled.public final boolean isDone()
true only if the task completed.public final void setResult(T result, Throwable cause)
Note that this method never changes the state of this future.
result - The result of the task.cause - The cause of the task failure.public final void interruptTask()
public final Throwable getTaskCause()
Throwable that indicates the cause of failure.Throwable instance.public final T getResult() throws ExecutionException
CancellationException - The task was canceled.ExecutionException - The task caught an exception.public final void awaitCompletion(int state)
state - The current state of the future.public final boolean done(int expected,
int state,
T result,
Throwable cause)
expected - The expected internal state.state - The internal state to be set.result - The result of the target task.cause - The Throwable that indicates the cause of
failure.true on success.
false if another thread completed the task.public final T get() throws InterruptedException, ExecutionException
CancellationException - The task was canceled.InterruptedException - The current thread was interrupted while waiting.ExecutionException - The task caught an exception.public final T get(long nano) throws InterruptedException, ExecutionException, TimeoutException
nano - The number of nanoseconds to wait.CancellationException - The task was canceled.InterruptedException - The current thread was interrupted while waiting.ExecutionException - The task caught an exception.TimeoutException - The task did not complete within the given timeout.protected final int tryAcquireShared(int arg)
tryAcquireShared in class AbstractQueuedSynchronizerarg - Unused.protected final boolean tryReleaseShared(int state)
tryReleaseShared in class AbstractQueuedSynchronizerstate - The internal state to be set.true is always returned.Copyright © 2018 OpenDaylight. All rights reserved.