Top Description Inners Fields Constructors Methods
com.google.common.util.concurrent

pack-priv Class ImmediateFuture<V extends @Nullable Object>

extends Object
implements ListenableFuture<V extends @Nullable Object>
Class Inheritance
All Implemented Interfaces
com.google.common.util.concurrent.ListenableFuture, java.util.concurrent.Future
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

Implementation of Futures#immediateFuture.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final LazyLogger
pack-priv static final ListenableFuture<?>
private final V

Constructor Summary

AccessConstructor and Description
pack-priv
ImmediateFuture(V value)

Method Summary

Modifier and TypeMethod and Description
public void
addListener(Runnable
the listener to run when the computation is complete
listener
,
Executor
the executor to run the listener in
executor
)

Implements com.google.common.util.concurrent.ListenableFuture.addListener.

Registers a listener to be run on the given executor.
public boolean
cancel(boolean
true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.
public V
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.
public V
get(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
public boolean
isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.
public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

logback to summary
private static final LazyLogger log
NULLback to summary
pack-priv static final ListenableFuture<?> NULL
valueback to summary
private final V value
Annotations
@ParametricNullness

Constructor Detail

ImmediateFutureback to summary
pack-priv ImmediateFuture(V value)

Method Detail

addListenerback to summary
public void addListener(Runnable listener, Executor executor)

Implements com.google.common.util.concurrent.ListenableFuture.addListener.

Doc from com.google.common.util.concurrent.ListenableFuture.addListener.

Registers a listener to be run on the given executor. The listener will run when the Future's computation is complete or, if the computation is already complete, immediately.

There is no guaranteed ordering of execution of listeners, but any listener added through this method is guaranteed to be called once the computation is complete.

Exceptions thrown by a listener will be propagated up to the executor. Any exception thrown during Executor.execute (e.g., a RejectedExecutionException or an exception thrown by direct execution) will be caught and logged.

Note

If your listener is lightweight -- and will not cause stack overflow by completing more futures or adding more directExecutor() listeners inline -- consider MoreExecutors#directExecutor. Otherwise, avoid it: See the warnings on the docs for directExecutor.

This is the most general listener interface. For common operations performed using listeners, see Futures. For a simplified but general listener interface, see addCallback().

Memory consistency effects: Actions in a thread prior to adding a listener happen-before its execution begins, perhaps in another thread.

Guava implementations of ListenableFuture promptly release references to listeners after executing them.

Parameters
listener:Runnable

the listener to run when the computation is complete

executor:Executor

the executor to run the listener in

Annotations
@Override
@SuppressWarnings:CatchingUnchecked
cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Parameters
mayInterruptIfRunning:boolean

true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete

Returns:boolean

false if the task could not be cancelled, typically because it has already completed; true otherwise. If two or more threads cause a task to be cancelled, then at least one of them returns true. Implementations may provide stronger guarantees.

Annotations
@Override
getback to summary
public V get()

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Returns:V

the computed result

Annotations
@Override
@ParametricNullness
getback to summary
public V get(long timeout, TimeUnit unit) throws ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:V

the computed result

Annotations
@Override
@ParametricNullness
Exceptions
ExecutionException:
if the computation threw an exception
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Returns:boolean

true if this task was cancelled before it completed

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:boolean

true if this task completed

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.google.common.util.concurrent back to summary

pack-priv final Class ImmediateFuture.ImmediateCancelledFuture<V extends @Nullable Object>

extends AbstractFuture.TrustedFuture<V extends @Nullable Object>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv static final ImmediateFuture.ImmediateCancelledFuture<Object>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from com.google.common.util.concurrent.AbstractFuture.TrustedFuture:
addListenercancelgetgetisCancelledisDone

Field Detail

INSTANCEback to summary
pack-priv static final ImmediateFuture.ImmediateCancelledFuture<Object> INSTANCE
Annotations
@CheckForNull

Constructor Detail

ImmediateCancelledFutureback to summary
pack-priv ImmediateCancelledFuture()
com.google.common.util.concurrent back to summary

pack-priv final Class ImmediateFuture.ImmediateFailedFuture<V extends @Nullable Object>

extends AbstractFuture.TrustedFuture<V extends @Nullable Object>
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from com.google.common.util.concurrent.AbstractFuture.TrustedFuture:
addListenercancelgetgetisCancelledisDone

Constructor Detail

ImmediateFailedFutureback to summary
pack-priv ImmediateFailedFuture(Throwable thrown)