groovyx.gpars.dataflow
Interface Promise<T>

All Known Implementing Classes:
DataflowVariable, DataflowVariable.RemoteDataflowVariable, SyncDataflowVariable

public interface Promise<T>

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

Author:
Vaclav Pech

Method Summary
 T get()
          Retrieves the value of the variable, blocking until a value is available
 T 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()
          Blocks, if the value has not been assigned yet to the DataflowVariable
 void join(long timeout, java.util.concurrent.TimeUnit units)
          Blocks, if the value has not been assigned yet to the DataflowVariable
<V> Promise<V>
rightShift(groovy.lang.Closure<V> closure)
          Schedule closure to be executed after data became available.
<V> Promise<V>
then(groovy.lang.Closure<V> closure)
          Schedule closure to be executed after data became available.
<V> Promise<V>
then(groovy.lang.Closure<V> closure, groovy.lang.Closure<V> errorHandler)
          Schedule closure to be executed after data became available.
<V> Promise<V>
then(PGroup group, groovy.lang.Closure<V> closure)
          Schedule closure to be executed after data becomes available.
<V> Promise<V>
then(PGroup group, groovy.lang.Closure<V> closure, groovy.lang.Closure<V> errorHandler)
          Schedule closure to be executed after data becomes available.
<V> Promise<V>
then(Pool pool, groovy.lang.Closure<V> closure)
          Schedule closure to be executed after data becomes available.
<V> Promise<V>
then(Pool pool, groovy.lang.Closure<V> closure, groovy.lang.Closure<V> errorHandler)
          Schedule closure to be executed after data becomes available.
<V> void
whenBound(groovy.lang.Closure<V> 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
<V> void
whenBound(PGroup group, groovy.lang.Closure<V> closure)
          Schedule closure to be executed after data becomes available.
<V> void
whenBound(Pool pool, groovy.lang.Closure<V> closure)
          Schedule closure to be executed after data becomes available.
 

Method Detail

get

T get()
      throws java.lang.Throwable
Retrieves the value of the variable, blocking until a value is available

Returns:
The value stored in the variable
Throws:
java.lang.Throwable - If the stored value is an exception instance it gets re-thrown

get

T get(long timeout,
      java.util.concurrent.TimeUnit units)
      throws java.lang.Throwable
Retrieves the value of the variable, blocking up to given timeout, if the value has not been assigned yet.

Parameters:
timeout - The timeout value
units - Units for the timeout
Returns:
The value stored in the variable
Throws:
java.lang.Throwable - If the stored value is an exception instance it gets re-thrown

join

void join()
          throws java.lang.InterruptedException
Blocks, if the value has not been assigned yet to the DataflowVariable

Throws:
java.lang.InterruptedException - If the current thread gets interrupted while waiting for the variable to be bound

join

void join(long timeout,
          java.util.concurrent.TimeUnit units)
          throws java.lang.InterruptedException
Blocks, if the value has not been assigned yet to the DataflowVariable

Parameters:
timeout - The timeout value
units - Units for the timeout
Throws:
java.lang.InterruptedException - If the current thread gets interrupted while waiting for the variable to be bound

rightShift

<V> Promise<V> rightShift(groovy.lang.Closure<V> 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.

whenBound

<V> void whenBound(groovy.lang.Closure<V> 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

<V> void whenBound(Pool pool,
                   groovy.lang.Closure<V> 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

<V> void whenBound(PGroup group,
                   groovy.lang.Closure<V> 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

void whenBound(MessageStream stream)
Send the bound data to provided stream when it becomes available

Parameters:
stream - stream where to send result

then

<V> Promise<V> then(groovy.lang.Closure<V> 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

<V> Promise<V> then(Pool pool,
                    groovy.lang.Closure<V> 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

<V> Promise<V> then(PGroup group,
                    groovy.lang.Closure<V> 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

<V> Promise<V> then(groovy.lang.Closure<V> closure,
                    groovy.lang.Closure<V> 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

<V> Promise<V> then(Pool pool,
                    groovy.lang.Closure<V> closure,
                    groovy.lang.Closure<V> 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

<V> Promise<V> then(PGroup group,
                    groovy.lang.Closure<V> closure,
                    groovy.lang.Closure<V> 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.

isBound

boolean isBound()
Check if value has been set already for this expression

Returns:
true if bound already

isError

boolean isError()
Checks if the promise is bound to an error

Returns:
True, if an error has been bound

getError

java.lang.Throwable getError()
Returns the error bound to the promise

Returns:
The error
Throws:
java.lang.IllegalStateException - If not bound or not bound to an error

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