Package org.ptolemy.commons
Class FutureValue<V>
- java.lang.Object
-
- org.ptolemy.commons.FutureValue<V>
-
- All Implemented Interfaces:
java.io.Serializable,java.util.concurrent.Future<V>
public class FutureValue<V> extends java.lang.Object implements java.util.concurrent.Future<V>, java.io.SerializableA Future implementation that just waits until its result value/exception is available.- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- ErwinDL
- See Also:
- Serialized Form
- Pt.AcceptedRating:
- Yellow (ErwinDL)
- Pt.ProposedRating:
- Yellow (ErwinDL)
-
-
Constructor Summary
Constructors Constructor Description FutureValue()Creates a future that will be waiting for its result.FutureValue(V value)Creates a future that is immediately set with its result value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_done()Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).booleancancel(boolean mayInterruptIfRunning)Vget()Vget(long timeout, java.util.concurrent.TimeUnit unit)booleanisCancelled()booleanisDone()voidset(V v)Sets the result of this Future to the given value unless this future has already been set or has been cancelled.voidsetException(java.lang.Throwable t)Causes this future to report an ExecutionException with the given throwable as its cause, unless this Future has already been set or has been cancelled.java.lang.StringtoString()
-
-
-
Constructor Detail
-
FutureValue
public FutureValue()
Creates a future that will be waiting for its result.
-
FutureValue
public FutureValue(V value)
Creates a future that is immediately set with its result value.- Parameters:
value- the future's result
-
-
Method Detail
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfacejava.util.concurrent.Future<V>
-
isDone
public boolean isDone()
- Specified by:
isDonein interfacejava.util.concurrent.Future<V>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancelin interfacejava.util.concurrent.Future<V>- Parameters:
mayInterruptIfRunning- ignored in this simple value-based implementation
-
get
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
getin interfacejava.util.concurrent.Future<V>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
get
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
getin interfacejava.util.concurrent.Future<V>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
set
public void set(V v)
Sets the result of this Future to the given value unless this future has already been set or has been cancelled.- Parameters:
v- the value
-
setException
public void setException(java.lang.Throwable t)
Causes this future to report an ExecutionException with the given throwable as its cause, unless this Future has already been set or has been cancelled.- Parameters:
t- the cause of failure
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
_done
protected void _done()
Protected method invoked when this task transitions to state isDone (whether normally or via cancellation). The default implementation does nothing. Subclasses may override this method to invoke completion callbacks or perform bookkeeping.
-
-