org.almendra.commons.threads
Class FutureResult

java.lang.Object
  extended by org.almendra.commons.threads.Future
      extended by org.almendra.commons.threads.FutureResult
All Implemented Interfaces:
IHistorizable, INamedObject, ISignalable

public class FutureResult
extends Future

Holds a promise to deliver a result after unlimited time or after a specifiable period. Used to make the calling thread wait until the result has been produced by some other thread. Upon arrival of the result the calling thread is unblocked or when the timeout period has expired. In the latter case null is returned as the result.

Author:
Oliver Plohmann

Field Summary
protected  java.io.Serializable result
          Attribute used to store the result the calling thread is asking for.
 
Fields inherited from class org.almendra.commons.threads.Future
exception, historyItems, holds, latch, lock, name, signaled, timeoutOccurred, verbose
 
Constructor Summary
FutureResult()
          Creates a new FutureResult object.
FutureResult(java.lang.String name)
          Creates a new FutureResult object.
FutureResult(java.lang.String name, boolean verbose)
          Creates a new FutureResult object.
 
Method Summary
 java.io.Serializable getResult()
           
 java.io.Serializable getResult(int timeoutPeriod)
          Returns the result.
 void setResult(java.io.Serializable result)
           
 
Methods inherited from class org.almendra.commons.threads.Future
acquire, acquire, addHistoryItems, createHistorySummary, getException, getHistoryItems, getName, hasException, holds, isTimeout, isVerbose, primAcquire, setException, setVerbose, signal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

result

protected java.io.Serializable result
Attribute used to store the result the calling thread is asking for.

Constructor Detail

FutureResult

public FutureResult()
Creates a new FutureResult object.


FutureResult

public FutureResult(java.lang.String name)
Creates a new FutureResult object.

Parameters:
name - the user-defined name of the future

FutureResult

public FutureResult(java.lang.String name,
                    boolean verbose)
Creates a new FutureResult object.

Parameters:
name - the user-defined name of the future
verbose - indicates whether trace information should be written to the console
Method Detail

getResult

public java.io.Serializable getResult()
Returns:
Returns the result.

getResult

public java.io.Serializable getResult(int timeoutPeriod)
                               throws java.lang.IllegalArgumentException,
                                      TimeoutException
Returns the result. Blocks till result has arrived or timeout has occurred.

Parameters:
timeoutPeriod - timeout period in milliseconds
Returns:
the result
Throws:
java.lang.IllegalArgumentException
TimeoutException

setResult

public void setResult(java.io.Serializable result)
Parameters:
result - The result to set.