|
|||||||||
| Home >> All >> org >> ematgine >> utils >> [ concurrent overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.ematgine.utils.concurrent
Class FutureResult

java.lang.Objectorg.ematgine.utils.concurrent.FutureResult
- public class FutureResult
- extends java.lang.Object
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. ]
| Field Summary | |
protected java.lang.reflect.InvocationTargetException |
exception_
the exception encountered by operation producing result |
protected boolean |
ready_
Status -- true after first set |
protected java.lang.Object |
value_
The result of the operation |
| Constructor Summary | |
FutureResult()
Create an initially unset FutureResult |
|
| Method Summary | |
void |
clear()
Clear the value and exception and set to not-ready, allowing this FutureResult to be reused. |
protected java.lang.Object |
doGet()
internal utility: either get the value or throw the exception |
java.lang.Object |
get()
Access the reference, waiting if necessary until it is ready. |
java.lang.reflect.InvocationTargetException |
getException()
Get the exception, or null if there isn't one (yet). |
boolean |
isReady()
Return whether the reference or exception have been set. |
java.lang.Object |
peek()
Access the reference, even if not ready |
void |
set(java.lang.Object newValue)
Set the reference, and signal that it is ready. |
void |
setException(java.lang.Throwable ex)
Set the exception field, also setting ready status. |
java.lang.Runnable |
setter(Callable function)
Return a Runnable object that, when run, will set the result value. |
java.lang.Object |
timedGet(long msecs)
Wait at most msecs to access the reference. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
value_
protected java.lang.Object value_
- The result of the operation
ready_
protected boolean ready_
- Status -- true after first set
exception_
protected java.lang.reflect.InvocationTargetException exception_
- the exception encountered by operation producing result
| Constructor Detail |
FutureResult
public FutureResult()
- Create an initially unset FutureResult
| Method Detail |
setter
public java.lang.Runnable setter(Callable function)
- Return a Runnable object that, when run, will set the result value.
doGet
protected java.lang.Object doGet() throws java.lang.reflect.InvocationTargetException
- internal utility: either get the value or throw the exception
get
public java.lang.Object get() throws java.lang.InterruptedException, java.lang.reflect.InvocationTargetException
- Access the reference, waiting if necessary until it is ready.
timedGet
public java.lang.Object timedGet(long msecs) throws TimeoutException, java.lang.InterruptedException, java.lang.reflect.InvocationTargetException
- Wait at most msecs to access the reference.
set
public void set(java.lang.Object newValue)
- 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.
setException
public void setException(java.lang.Throwable ex)
- Set the exception field, also setting ready status.
getException
public java.lang.reflect.InvocationTargetException getException()
- 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.
isReady
public boolean isReady()
- Return whether the reference or exception have been set.
peek
public java.lang.Object peek()
- Access the reference, even if not ready
clear
public void clear()
- 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.
|
|||||||||
| Home >> All >> org >> ematgine >> utils >> [ concurrent overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.ematgine.utils.concurrent.FutureResult