net.sf.asyncobjects.util
Class Wait

java.lang.Object
  extended by net.sf.asyncobjects.util.Wait

public class Wait
extends Object

This utility class allows waiting on some conditions related to promises.


Constructor Summary
Wait()
           
 
Method Summary
static Promise<Object[]> all(Promise<?>... promises)
          This method allows waiting until operations represented by promises will finish.
static Promise<Object> any(boolean ignoreFailures, Collection<?> values)
          A utilty variant of any(boolean, Iterator) method that gets a Collection as argument.
static Promise<Object> any(boolean ignoreFailures, Iterator<Object> values)
          Calculate first ready value of failure from the iterator.
static Promise<Object> any(boolean ignoreFailures, Object[] values)
          A utilty variant of any(boolean, Iterator) method that gets an array as argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Wait

public Wait()
Method Detail

all

public static Promise<Object[]> all(Promise<?>... promises)
This method allows waiting until operations represented by promises will finish.

Parameters:
promises - an array of promises to watch. Null is considered to be promise that is already resolved to null.
Returns:
a promise that resolves to array of results if all operations finished successfully, or smashed with exception WaitAllException if there are one or more failures.

any

public static Promise<Object> any(boolean ignoreFailures,
                                  Iterator<Object> values)
Calculate first ready value of failure from the iterator. The method returns pormise for first ready value in the iterator. The following value kinds are recognized:
Promise
A value of promise is ready when it is resolved. A value of resolved promise is treated as scalar.
AsyncObject
If object is immediate, it is treated as scalar otherwise as unresolved promise.
AsyncAction
The action is executed using AsyncAction.executeNow() method. The result is interpreted as for promise. This is used to express lazy values for this method.
Compensated
First value is got using Compensated.run() method. If value or failure is not used, they are compensated with Compensated.compensateValue(Object) and Compensated.compensateFailure(Throwable) method correspondingly. As soon as it known that value will not be used, the method Compensated.cancel() is called.
Scalar value
Any other value is treated as scalar value. The execution stops when first scalar value is encountered in array.

Parameters:
ignoreFailures - if this flag true, failures are not treated as normal return values. The method instead tries to receive success result first. only if all branches failed, first received failure made result of any construct.
values - an iterator over values. If iterator is empty, the method finishes with exception. Iterator is assumed to never throw an exception if Iterator.hasNext() method was successful. However failure can be expressed as smashed promise.
Returns:
a promise for the first value or failure

any

public static Promise<Object> any(boolean ignoreFailures,
                                  Collection<?> values)
A utilty variant of any(boolean, Iterator) method that gets a Collection as argument.

Parameters:
ignoreFailures - if true, failures are ignored
values - a collection of asynchronous results
Returns:
a promise for result of computation

any

public static Promise<Object> any(boolean ignoreFailures,
                                  Object[] values)
A utilty variant of any(boolean, Iterator) method that gets an array as argument.

Parameters:
ignoreFailures - if true, failures are ignored
values - a collection of asynchronous results
Returns:
a promise for result of computation


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.