| java.lang.Object EDU.oswego.cs.dl.util.concurrent.FutureResult
FutureResult | public class FutureResult (Code) | | A class maintaining a single reference variable serving as the result
of an operation. The result cannot be accessed until it has been set.
Sample Usage
class ImageRenderer { Image render(byte[] raw); }
class App {
Executor executor = ...
ImageRenderer renderer = ...
void display(byte[] rawimage) {
try {
FutureResult futureImage = new FutureResult();
Runnable command = futureImage.setter(new Callable() {
public Object call() { return renderer.render(rawImage); }
});
executor.execute(command);
drawBorders(); // do other things while executing
drawCaption();
drawImage((Image)(futureImage.get())); // use future
}
catch (InterruptedException ex) { return; }
catch (InvocationTargetException ex) { cleanup(); return; }
}
}
[ Introduction to this package. ]
See Also: Executor |
Method Summary | |
public synchronized void | clear() Clear the value and exception and set to not-ready,
allowing this FutureResult to be reused. | protected Object | doGet() | public synchronized Object | get() Access the reference, waiting if necessary until it is ready. | public synchronized InvocationTargetException | getException() Get the exception, or null if there isn't one (yet). | public synchronized boolean | isReady() Return whether the reference or exception have been set.
true if has been set. | public synchronized Object | peek() | public synchronized void | set(Object newValue) Set the reference, and signal that it is ready. | public synchronized void | setException(Throwable ex) Set the exception field, also setting ready status.
Parameters: ex - The exception. | public Runnable | setter(Callable function) Return a Runnable object that, when run, will set the result value.
Parameters: function - - a Callable object whose result will beheld by this FutureResult. | public synchronized Object | timedGet(long msecs) Wait at most msecs to access the reference. |
ready_ | protected boolean ready_(Code) | | Status -- true after first set *
|
value_ | protected Object value_(Code) | | The result of the operation *
|
FutureResult | public FutureResult()(Code) | | Create an initially unset FutureResult
|
clear | public synchronized void clear()(Code) | | Clear the value and exception and set to not-ready,
allowing this FutureResult to be reused. This is not
particularly recommended and must be done only
when you know that no other object is depending on the
properties of this FutureResult.
|
getException | public synchronized InvocationTargetException getException()(Code) | | Get the exception, or null if there isn't one (yet).
This does not wait until the future is ready, so should
ordinarily only be called if you know it is.
the exception encountered by the operationsetting the future, wrapped in an InvocationTargetException |
isReady | public synchronized boolean isReady()(Code) | | Return whether the reference or exception have been set.
true if has been set. else false |
peek | public synchronized Object peek()(Code) | | Access the reference, even if not ready
current value |
set | public synchronized void set(Object newValue)(Code) | | Set the reference, and signal that it is ready. It is not
considered an error to set the value more than once,
but it is not something you would normally want to do.
Parameters: newValue - The value that will be returned by a subsequent get(); |
setException | public synchronized void setException(Throwable ex)(Code) | | Set the exception field, also setting ready status.
Parameters: ex - The exception. It will be reported out wrappedwithin an InvocationTargetException |
setter | public Runnable setter(Callable function)(Code) | | Return a Runnable object that, when run, will set the result value.
Parameters: function - - a Callable object whose result will beheld by this FutureResult. A Runnable object that, when run, will call thefunction and (eventually) set the result. |
|
|