com.google.common.util.concurrent
Class ValueFuture<V>

java.lang.Object
  extended by com.google.common.util.concurrent.AbstractFuture<V>
      extended by com.google.common.util.concurrent.AbstractListenableFuture<V>
          extended by com.google.common.util.concurrent.ValueFuture<V>
All Implemented Interfaces:
ListenableFuture<V>, Future<V>

public class ValueFuture<V>
extends AbstractListenableFuture<V>

A simple ListenableFuture that holds a value or an exception.

Since:
2009.09.15 tentative
Author:
Sven Mawson

Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
          
static
<T> ValueFuture<T>
create()
          Creates a new ValueFuture in the default state.
 boolean set(V newValue)
          Sets the value of this future.
 boolean setException(Throwable t)
          Sets the future to having failed with the given exception.
 
Methods inherited from class com.google.common.util.concurrent.AbstractListenableFuture
addListener, done
 
Methods inherited from class com.google.common.util.concurrent.AbstractFuture
cancel, get, get, isCancelled, isDone
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.Future
get, get, isCancelled, isDone
 

Method Detail

create

public static <T> ValueFuture<T> create()
Creates a new ValueFuture in the default state.


set

public boolean set(V newValue)
Sets the value of this future. This method will return true if the value was successfully set, or false if the future has already been set or cancelled.

Overrides:
set in class AbstractFuture<V>
Parameters:
newValue - the value the future should hold.
Returns:
true if the value was successfully set.

setException

public boolean setException(Throwable t)
Sets the future to having failed with the given exception. This exception will be wrapped in an ExecutionException and thrown from the get methods. This method will return true if the exception was successfully set, or false if the future has already been set or cancelled.

Overrides:
setException in class AbstractFuture<V>
Parameters:
t - the exception the future should hold.
Returns:
true if the exception was successfully set.

cancel

public boolean cancel(boolean mayInterruptIfRunning)

A ValueFuture is never considered in the running state, so the mayInterruptIfRunning argument is ignored.

Specified by:
cancel in interface Future<V>
Overrides:
cancel in class AbstractFuture<V>