类 DefaultFuture<V>
- 所有已实现的接口:
ListenableFuture<V>,SettableFuture<V>,Future<V>
- 从以下版本开始:
- 4.0 2024/2/26 17:27
- 作者:
- Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明private static final classprivate static final classprivate static final class -
字段概要
字段修饰符和类型字段说明private static final DefaultFuture.CauseHolderprivate static final StackTraceElement[](专用程序包) static final Executorprivate final Executorprivate FutureListener<? extends ListenableFuture<?>>One or more listeners.private FutureListenersprivate static final Loggerprivate booleanThreading - synchronized(this).private static final Loggerprivate Objectprivate static final AtomicReferenceFieldUpdater<DefaultFuture,Object> private static final Objectprivate static final Objectprivate shortThreading - synchronized(this). -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明addListener(FutureListener<? extends ListenableFuture<V>> listener) Adds the specified listener to this future.addListeners(FutureListener<? extends ListenableFuture<V>>... listeners) Adds the specified listeners to this future.await()Waits for this future to be completed.booleanawait(long timeoutMillis) Waits for this future to be completed within the specified time limit.booleanWaits for this future to be completed within the specified time limit.Waits for this future to be completed without interruption.booleanawaitUninterruptibly(long timeoutMillis) Waits for this future to be completed within the specified time limit without interruption.booleanawaitUninterruptibly(long timeout, TimeUnit unit) Waits for this future to be completed within the specified time limit without interruption.booleancancel(boolean mayInterruptIfRunning) If the cancellation was successful it will fail the future with aCancellationException.private booleanCheck if there are any waiters and if so notify these.private voidprivate voiddoAddListener(FutureListener<? extends ListenableFuture<V>> listener) private booleandoAwait(long timeoutNanos, boolean interruptable) private voiddoRemoveListener(FutureListener<? extends ListenableFuture<V>> toRemove) private booleandoSetFailure(Throwable cause) private booleandoSetSuccess(V result) private booleandoSetValue(Object objResult) get()getCause()Returns the cause of the failed operation if the operation failed.private ThrowablegetNow()Return the result without blocking.private voidprotected voidSubclasses can override this method to implement interruption of the future's computation.booleanbooleanprivate static booleanisCancelled(Object result) booleanisDone()private static booleanbooleanReturnstrueif and only if the operation was completed successfully.private static voidnotifyListener(ListenableFuture future, FutureListener l) protected static voidnotifyListener(Executor executor, ListenableFuture<?> future, FutureListener<?> listener) Notify a listener that a future has completed.private voidprivate voidnotifyListeners(FutureListeners listeners) private voidprivate static voidnotifyProgressiveListener(ProgressiveFuture future, ProgressiveFutureListener l, long progress, long total) (专用程序包) voidnotifyProgressiveListeners(long progress, long total) Notify all progressive listeners.private static voidnotifyProgressiveListeners(ProgressiveFuture<?> future, ProgressiveFutureListener<?>[] listeners, long progress, long total) private ObjectremoveListener(FutureListener<? extends ListenableFuture<V>> listener) Removes the first occurrence of the specified listener from this future.removeListeners(FutureListener<? extends ListenableFuture<V>>... listeners) Removes the first occurrence for each of the listeners from this future.private voidprivate static voidsafeExecute(Executor executor, Runnable task) setFailure(Throwable cause) Marks this future as a failure and notifies all listeners.setSuccess(V result) Marks this future as a success and notifies all listeners.booleanMake this future impossible to cancel.sync()Waits for this future until it is done, and rethrows the cause of the failure if this future failed.Waits for this future until it is done, and rethrows the cause of the failure if this future failed.toString()protected StringBuilderbooleantryFailure(Throwable cause) Marks this future as a failure and notifies all listeners.booleantrySuccess(V result) Marks this future as a success and notifies all listeners.从类继承的方法 cn.taketoday.util.concurrent.AbstractFuture
obtain从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait从接口继承的方法 cn.taketoday.util.concurrent.ListenableFuture
completable, obtain从接口继承的方法 cn.taketoday.util.concurrent.SettableFuture
addListener, onFailure, onSuccess
-
字段详细资料
-
logger
-
rejectedExecutionLogger
-
RESULT_UPDATER
-
SUCCESS
-
UNCANCELLABLE
-
CANCELLATION_CAUSE_HOLDER
-
CANCELLATION_STACK
-
defaultExecutor
-
executor
-
result
-
listener
One or more listeners. Can be aFutureListeneror aFutureListeners. Ifnull, it means either 1) no listeners were added yet or 2) all listeners were notified. Threading - synchronized(this). We must support adding listeners when there is no Executor. -
listeners
-
waiters
private short waitersThreading - synchronized(this). We are required to hold the monitor to use Java's underlying wait()/notifyAll(). -
notifyingListeners
private boolean notifyingListenersThreading - synchronized(this). We must prevent concurrent notification and FIFO listener notification if the executor changes.
-
-
构造器详细资料
-
DefaultFuture
public DefaultFuture()Creates a new instance. -
DefaultFuture
Creates a new instance.- 参数:
executor- theExecutorwhich is used to notify the SettableFuture once it is complete.
-
-
方法详细资料
-
addListener
从接口复制的说明:ListenableFutureAdds the specified listener to this future.The specified listener is notified when this future is done. If this future is already completed, the specified listener is notified immediately.
- 指定者:
addListener在接口中ListenableFuture<V>- 指定者:
addListener在接口中SettableFuture<V>
-
addListeners
从接口复制的说明:ListenableFutureAdds the specified listeners to this future.The specified listeners are notified when this future is done. If this future is already completed, the specified listeners are notified immediately.
- 指定者:
addListeners在接口中ListenableFuture<V>- 指定者:
addListeners在接口中SettableFuture<V>
-
removeListener
从接口复制的说明:ListenableFutureRemoves the first occurrence of the specified listener from this future.The specified listener is no longer notified when this future is done. If the specified listener is not associated with this future, this method does nothing and returns silently.
- 指定者:
removeListener在接口中ListenableFuture<V>- 指定者:
removeListener在接口中SettableFuture<V>
-
removeListeners
public SettableFuture<V> removeListeners(FutureListener<? extends ListenableFuture<V>>... listeners) 从接口复制的说明:ListenableFutureRemoves the first occurrence for each of the listeners from this future.The specified listeners are no longer notified when this future is done. If the specified listeners are not associated with this future, this method does nothing and returns silently.
- 指定者:
removeListeners在接口中ListenableFuture<V>- 指定者:
removeListeners在接口中SettableFuture<V>
-
setSuccess
从接口复制的说明:SettableFutureMarks this future as a success and notifies all listeners. If it is success or failed already it will throw anIllegalStateException.- 指定者:
setSuccess在接口中SettableFuture<V>
-
trySuccess
从接口复制的说明:SettableFutureMarks this future as a success and notifies all listeners.- 指定者:
trySuccess在接口中SettableFuture<V>- 返回:
trueif and only if successfully marked this future as a success. Otherwisefalsebecause this future is already marked as either a success or a failure.
-
setFailure
从接口复制的说明:SettableFutureMarks this future as a failure and notifies all listeners. If it is success or failed already it will throw anIllegalStateException.- 指定者:
setFailure在接口中SettableFuture<V>
-
tryFailure
从接口复制的说明:SettableFutureMarks this future as a failure and notifies all listeners.- 指定者:
tryFailure在接口中SettableFuture<V>- 返回:
trueif and only if successfully marked this future as a failure. Otherwisefalsebecause this future is already marked as either a success or a failure.
-
setUncancellable
public boolean setUncancellable()从接口复制的说明:SettableFutureMake this future impossible to cancel.- 指定者:
setUncancellable在接口中SettableFuture<V>- 返回:
trueif and only if successfully marked this future as uncancellable or it is already done without being cancelled.falseif this future has been cancelled already.
-
isSuccess
public boolean isSuccess()从接口复制的说明:ListenableFutureReturnstrueif and only if the operation was completed successfully.- 指定者:
isSuccess在接口中ListenableFuture<V>
-
isCancellable
public boolean isCancellable()- 指定者:
isCancellable在接口中ListenableFuture<V>- 返回:
- returns
trueif and only if the operation can be cancelled viaListenableFuture.cancel(boolean).
-
isCancelled
public boolean isCancelled()- 指定者:
isCancelled在接口中Future<V>
-
isDone
public boolean isDone() -
getCause
从接口复制的说明:ListenableFutureReturns the cause of the failed operation if the operation failed.- 指定者:
getCause在接口中ListenableFuture<V>- 返回:
- the cause of the failure.
nullif succeeded or this future is not completed yet.
-
getCause
-
sync
从接口复制的说明:ListenableFutureWaits for this future until it is done, and rethrows the cause of the failure if this future failed.- 指定者:
sync在接口中ListenableFuture<V>- 指定者:
sync在接口中SettableFuture<V>- 抛出:
InterruptedException
-
syncUninterruptibly
从接口复制的说明:ListenableFutureWaits for this future until it is done, and rethrows the cause of the failure if this future failed.- 指定者:
syncUninterruptibly在接口中ListenableFuture<V>- 指定者:
syncUninterruptibly在接口中SettableFuture<V>
-
await
从接口复制的说明:ListenableFutureWaits for this future to be completed.- 指定者:
await在接口中ListenableFuture<V>- 指定者:
await在接口中SettableFuture<V>- 抛出:
InterruptedException- if the current thread was interrupted
-
awaitUninterruptibly
从接口复制的说明:ListenableFutureWaits for this future to be completed without interruption. This method catches anInterruptedExceptionand discards it silently.- 指定者:
awaitUninterruptibly在接口中ListenableFuture<V>- 指定者:
awaitUninterruptibly在接口中SettableFuture<V>
-
await
从接口复制的说明:ListenableFutureWaits for this future to be completed within the specified time limit.- 指定者:
await在接口中ListenableFuture<V>- 返回:
trueif and only if the future was completed within the specified time limit- 抛出:
InterruptedException- if the current thread was interrupted
-
await
从接口复制的说明:ListenableFutureWaits for this future to be completed within the specified time limit.- 指定者:
await在接口中ListenableFuture<V>- 返回:
trueif and only if the future was completed within the specified time limit- 抛出:
InterruptedException- if the current thread was interrupted
-
awaitUninterruptibly
从接口复制的说明:ListenableFutureWaits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedExceptionand discards it silently.- 指定者:
awaitUninterruptibly在接口中ListenableFuture<V>- 返回:
trueif and only if the future was completed within the specified time limit
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis) 从接口复制的说明:ListenableFutureWaits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedExceptionand discards it silently.- 指定者:
awaitUninterruptibly在接口中ListenableFuture<V>- 返回:
trueif and only if the future was completed within the specified time limit
-
getNow
从接口复制的说明:ListenableFutureReturn the result without blocking. If the future is not done yet this will returnnull.As it is possible that a
nullvalue is used to mark the future as successful you also need to check if the future is really done withFuture.isDone()and not rely on the returnednullvalue.- 指定者:
getNow在接口中ListenableFuture<V>
-
get
- 指定者:
get在接口中Future<V>- 覆盖:
get在类中AbstractFuture<V>- 抛出:
InterruptedExceptionExecutionException
-
get
@Nullable public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - 指定者:
get在接口中Future<V>- 覆盖:
get在类中AbstractFuture<V>- 抛出:
InterruptedExceptionExecutionExceptionTimeoutException
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) If the cancellation was successful it will fail the future with aCancellationException. -
interruptTask
protected void interruptTask()Subclasses can override this method to implement interruption of the future's computation. The method is invoked automatically by a successful call tocancel(true).The default implementation is empty.
-
toString
-
toStringBuilder
-
notifyListener
protected static void notifyListener(@Nullable Executor executor, ListenableFuture<?> future, FutureListener<?> listener) Notify a listener that a future has completed.- 参数:
executor- the executor to use to notify the listenerlistener.future- the future that is complete.listener- the listener to notify.
-
notifyListeners
private void notifyListeners() -
notifyListenersNow
private void notifyListenersNow() -
notifyListeners
-
notifyListener
-
doAddListener
-
doRemoveListener
-
doSetSuccess
-
doSetFailure
-
doSetValue
-
checkNotifyWaiters
private boolean checkNotifyWaiters()Check if there are any waiters and if so notify these.- 返回:
trueif there are any listeners attached to the SettableFuture,falseotherwise.
-
incWaiters
private void incWaiters() -
decWaiters
private void decWaiters() -
rethrowIfFailed
private void rethrowIfFailed() -
doAwait
-
notifyProgressiveListeners
void notifyProgressiveListeners(long progress, long total) Notify all progressive listeners.No attempt is made to ensure notification order if multiple calls are made to this method before the original invocation completes.
This will do an iteration over all listeners to get all of type
ProgressiveFutureListeners.- 参数:
progress- the new progress.total- the total progress.
-
progressiveListeners
-
notifyProgressiveListeners
private static void notifyProgressiveListeners(ProgressiveFuture<?> future, ProgressiveFutureListener<?>[] listeners, long progress, long total) -
notifyProgressiveListener
private static void notifyProgressiveListener(ProgressiveFuture future, ProgressiveFutureListener l, long progress, long total) -
isCancelled
-
isDone
-
safeExecute
-