edu.vub.at.actors.eventloops
Class BlockingFuture

java.lang.Object
  extended byedu.vub.at.actors.eventloops.BlockingFuture
All Implemented Interfaces:
Future

public final class BlockingFuture
extends java.lang.Object
implements Future

A BlockingFuture represents a synchronous, blocking future used by the AT/2 implementation to synchronize between native threads. Usage: BlockingFuture future = object.doAsynchronousComputation(); try { Object result = future.get(); } catch(Exception e) { // async computation raised an exception } Based on source code written by Doug Lea with assistance from members of JCP JSR-166 Expert Group and released to the public domain.

Author:
tvcutsem

Field Summary
private  java.lang.Exception exception
           
private  boolean fulfilled
           
private  java.lang.Object result
           
 
Constructor Summary
BlockingFuture()
           
 
Method Summary
 java.lang.Object get()
          Used to retrieve the real value from the future.
private  java.lang.Object getResult()
          Gets the result of the task.
 boolean isDetermined()
           
 void resolve(java.lang.Object v)
          Sets the result of this Future to the given value unless this future has already been set or has been cancelled.
 void ruin(java.lang.Exception e)
          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.
private  void setCompleted(java.lang.Object result)
          Marks the task as completed.
private  void setFailed(java.lang.Exception exception)
          Marks the task as failed.
private  void waitFor()
          Waits for the task to complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

result

private java.lang.Object result

exception

private java.lang.Exception exception

fulfilled

private boolean fulfilled
Constructor Detail

BlockingFuture

public BlockingFuture()
Method Detail

isDetermined

public boolean isDetermined()

get

public java.lang.Object get()
                     throws java.lang.Exception
Description copied from interface: Future
Used to retrieve the real value from the future.

Specified by:
get in interface Future
Returns:
the resolved value of the future, once it is available.
Throws:
java.lang.Exception - if the future has been ruined with an exception.

resolve

public void resolve(java.lang.Object v)
Sets the result of this Future to the given value unless this future has already been set or has been cancelled.

Specified by:
resolve in interface Future
Parameters:
v - the value

ruin

public void ruin(java.lang.Exception e)
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.

Specified by:
ruin in interface Future
Parameters:
e - the cause of failure

setCompleted

private void setCompleted(java.lang.Object result)
Marks the task as completed.

Parameters:
result - the result of a task.

setFailed

private void setFailed(java.lang.Exception exception)
Marks the task as failed.

Parameters:
exception - the cause of abrupt completion.

waitFor

private void waitFor()
Waits for the task to complete. PRE: lock owned


getResult

private java.lang.Object getResult()
                            throws java.lang.Exception
Gets the result of the task. PRE: task completed PRE: lock owned

Throws:
java.lang.Exception