com.levigo.util.concurrent
Class SettableFuture<V>

java.lang.Object
  extended by com.levigo.util.concurrent.SettableFuture<V>
Type Parameters:
V - the value type
All Implemented Interfaces:
Future<V>

public class SettableFuture<V>
extends Object
implements Future<V>

An implementation of a Future. Its result may be set via set(Object), an error may be signalized via setError(Throwable). It may also be canceled via cancel(boolean).

This class will be superfluous with Java 8 since it provides the class java.util.concurrent.CompletableFuture with a lot more features.


Constructor Summary
SettableFuture()
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
 V get()
           
 V get(long timeout, TimeUnit unit)
           
 boolean isCancelled()
           
 boolean isDone()
           
 V poll()
          Gets the future result, but returns immediately if no result is available yet
 void set(V result)
          Set the result of this Future
 void setError(Throwable error)
          Signalize an error which will cause an ExecutionException on subsequent calls of the get methods
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SettableFuture

public SettableFuture()
Method Detail

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface Future<V>

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<V>

isDone

public boolean isDone()
Specified by:
isDone in interface Future<V>

poll

public V poll()
       throws ExecutionException
Gets the future result, but returns immediately if no result is available yet

Returns:
the future result or null if no result is available yet
Throws:
ExecutionException - if an error was signalized via setError(Throwable)
CancellationException - if the future was cancelled via cancel(boolean)

get

public V get()
      throws InterruptedException,
             ExecutionException
Specified by:
get in interface Future<V>
Throws:
InterruptedException
ExecutionException

get

public V get(long timeout,
             TimeUnit unit)
      throws InterruptedException,
             ExecutionException,
             TimeoutException
Specified by:
get in interface Future<V>
Throws:
InterruptedException
ExecutionException
TimeoutException

set

public void set(V result)
Set the result of this Future

Parameters:
result -
Throws:
IllegalStateException - if a result or an error has already been set

setError

public void setError(Throwable error)
Signalize an error which will cause an ExecutionException on subsequent calls of the get methods

Parameters:
error - the error
Throws:
IllegalStateException - if a result or an error has already been set


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.