org.codehaus.gpars

groovyx.gpars.dataflow
[Java] Interface Promise


public interface Promise

A unifying future-like interface to dataflow variables, asynchronous functions and active objects.

Authors:
Vaclav Pech


Method Summary
java.lang.Object get()

Retrieves the value of the variable, blocking until a value is available

java.lang.Object get(long timeout, java.util.concurrent.TimeUnit units)

Retrieves the value of the variable, blocking up to given timeout, if the value has not been assigned yet.

java.lang.Throwable getError()

Returns the error bound to the promise

boolean isBound()

Check if value has been set already for this expression

boolean isError()

Checks if the promise is bound to an error

void join()

// * Asynchronously retrieves the value from the channel.

void join(long timeout, java.util.concurrent.TimeUnit units)

Blocks, if the value has not been assigned yet to the DataflowVariable

Promise rightShift(groovy.lang.Closure closure)

Schedule closure to be executed after data became available.

Promise then(groovy.lang.Closure closure)

Schedule closure to be executed after data became available.

Promise then(Pool pool, groovy.lang.Closure closure)

Schedule closure to be executed after data becomes available.

Promise then(PGroup group, groovy.lang.Closure closure)

Schedule closure to be executed after data becomes available.

Promise then(groovy.lang.Closure closure, groovy.lang.Closure errorHandler)

Schedule closure to be executed after data became available.

Promise then(Pool pool, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)

Schedule closure to be executed after data becomes available.

Promise then(PGroup group, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)

Schedule closure to be executed after data becomes available.

void whenBound(groovy.lang.Closure closure)

Schedule closure to be executed after data becomes available.

void whenBound(Pool pool, groovy.lang.Closure closure)

Schedule closure to be executed after data becomes available.

void whenBound(PGroup group, groovy.lang.Closure closure)

Schedule closure to be executed after data becomes available.

void whenBound(MessageStream stream)

Send the bound data to provided stream when it becomes available

 

Method Detail

get

@SuppressWarnings({"ProhibitedExceptionDeclared"})
public java.lang.Object get()
Retrieves the value of the variable, blocking until a value is available
throws:
Throwable If the stored value is an exception instance it gets re-thrown
Returns:
The value stored in the variable


get

@SuppressWarnings({"ProhibitedExceptionDeclared"})
public java.lang.Object get(long timeout, java.util.concurrent.TimeUnit units)
Retrieves the value of the variable, blocking up to given timeout, if the value has not been assigned yet.
throws:
Throwable If the stored value is an exception instance it gets re-thrown
Parameters:
timeout - The timeout value
units - Units for the timeout
Returns:
The value stored in the variable


getError

public java.lang.Throwable getError()
Returns the error bound to the promise
throws:
IllegalStateException If not bound or not bound to an error
Returns:
The error


isBound

public boolean isBound()
Check if value has been set already for this expression
Returns:
true if bound already


isError

public boolean isError()
Checks if the promise is bound to an error
Returns:
True, if an error has been bound


join

public void join()
// * Asynchronously retrieves the value from the channel. Sends the actual value of the channel as a message // * back the the supplied actor once the value has been bound. // * The actor can perform other activities or release a thread back to the pool by calling react() waiting for the message // * with the value of the Dataflow channel. // * // *
Parameters:
callback - An actor to send the bound value to. //


join

public void join(long timeout, java.util.concurrent.TimeUnit units)
Blocks, if the value has not been assigned yet to the DataflowVariable
throws:
InterruptedException If the current thread gets interrupted while waiting for the variable to be bound
Parameters:
timeout - The timeout value
units - Units for the timeout


rightShift

public Promise rightShift(groovy.lang.Closure closure)
Schedule closure to be executed after data became available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled
Parameters:
closure - closure to execute when data becomes available. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

public Promise then(groovy.lang.Closure closure)
Schedule closure to be executed after data became available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled
Parameters:
closure - closure to execute when data becomes available. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

public Promise then(Pool pool, groovy.lang.Closure closure)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
pool - The thread pool to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

public Promise then(PGroup group, groovy.lang.Closure closure)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
group - The PGroup to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

public Promise then(groovy.lang.Closure closure, groovy.lang.Closure errorHandler)
Schedule closure to be executed after data became available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled
Parameters:
closure - closure to execute when data becomes available. The closure should take at most one argument.
errorHandler - closure to execute when an error (instance of Throwable) gets bound. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

public Promise then(Pool pool, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
pool - The thread pool to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.
errorHandler - closure to execute when an error (instance of Throwable) gets bound. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


then

public Promise then(PGroup group, groovy.lang.Closure closure, groovy.lang.Closure errorHandler)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
group - The PGroup to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.
errorHandler - closure to execute when an error (instance of Throwable) gets bound. The closure should take at most one argument.
Returns:
A promise for the results of the supplied closure. This allows for chaining of then() method calls.


whenBound

public void whenBound(groovy.lang.Closure closure)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
closure - closure to execute when data becomes available. The closure should take at most one argument.


whenBound

public void whenBound(Pool pool, groovy.lang.Closure closure)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
pool - The thread pool to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.


whenBound

public void whenBound(PGroup group, groovy.lang.Closure closure)
Schedule closure to be executed after data becomes available. It is important to notice that even if the expression is already bound the execution of closure will not happen immediately but will be scheduled.
Parameters:
group - The PGroup to use for task scheduling for asynchronous message delivery
closure - closure to execute when data becomes available. The closure should take at most one argument.


whenBound

public void whenBound(MessageStream stream)
Send the bound data to provided stream when it becomes available
Parameters:
stream - stream where to send result


 

Copyright © 2008–2012 Václav Pech. All Rights Reserved.