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.Serializable
A 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).boolean
cancel(boolean mayInterruptIfRunning)
V
get()
V
get(long timeout, java.util.concurrent.TimeUnit unit)
boolean
isCancelled()
boolean
isDone()
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.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.java.lang.String
toString()
-
-
-
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:
isCancelled
in interfacejava.util.concurrent.Future<V>
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfacejava.util.concurrent.Future<V>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancel
in 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:
get
in interfacejava.util.concurrent.Future<V>
- Throws:
java.lang.InterruptedException
java.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:
get
in interfacejava.util.concurrent.Future<V>
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.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:
toString
in 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.
-
-