groovyx.gpars.dataflow
Interface Promise<T>

All Known Implementing Classes:
DataflowVariable, DataflowVariable.RemoteDataflowVariable

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.
 T getVal()
          Reads the current value of the channel.
 T getVal(long timeout, java.util.concurrent.TimeUnit units)
          Reads the current value of the channel.
 void getValAsync(MessageStream callback)
          Asynchronously retrieves the value from the channel.
 void getValAsync(java.lang.Object attachment, MessageStream callback)
          Asynchronously retrieves the value from the channel.
 boolean isBound()
          Check if value has been set already for this expression
 void rightShift(groovy.lang.Closure closure)
          Schedule closure to be executed by pooled actor after data became available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled
 void whenBound(groovy.lang.Closure closure)
          Schedule closure to be executed by pooled actor after data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.
 void whenBound(MessageStream stream)
          Send the bound data to provided stream when it becomes available
 void whenBound(groovyx.gpars.group.PGroup group, groovy.lang.Closure closure)
          Schedule closure to be executed by pooled actor after data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.
 void whenBound(Pool pool, groovy.lang.Closure closure)
          Schedule closure to be executed by pooled actor after data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.
 

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

getValAsync

void getValAsync(MessageStream callback)
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.

getValAsync

void getValAsync(java.lang.Object attachment,
                 MessageStream callback)
Asynchronously retrieves the value from the channel. Sends a message back the the supplied MessageStream with a map holding the supplied attachment under the 'attachment' key and the actual value of the channel under the 'result' key once the value has been bound. Attachment is an arbitrary value helping the actor.operator match its request with the reply. The actor/operator 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:
attachment - arbitrary non-null attachment if reader needs better identification of result
callback - An actor to send the bound value plus the supplied index to.

getVal

T getVal()
         throws java.lang.InterruptedException
Reads the current value of the channel. Blocks, if the value has not been assigned yet.

Returns:
The actual value
Throws:
java.lang.InterruptedException - If the current thread gets interrupted while waiting for the channel to be bound

getVal

T getVal(long timeout,
         java.util.concurrent.TimeUnit units)
         throws java.lang.InterruptedException
Reads the current value of the channel. Blocks up to given timeout, if the value has not been assigned yet.

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

rightShift

void rightShift(groovy.lang.Closure closure)
Schedule closure to be executed by pooled actor after data became available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled

Parameters:
closure - closure to execute when data available

whenBound

void whenBound(groovy.lang.Closure closure)
Schedule closure to be executed by pooled actor after data becomes available It is important to notice that even if data already available the execution of closure will not happen immediately but will be scheduled.

Parameters:
closure - closure to execute when data available

whenBound

void whenBound(Pool pool,
               groovy.lang.Closure closure)
Schedule closure to be executed by pooled actor after data becomes available It is important to notice that even if data already available 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 available

whenBound

void whenBound(groovyx.gpars.group.PGroup group,
               groovy.lang.Closure closure)
Schedule closure to be executed by pooled actor after data becomes available It is important to notice that even if data already available 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 available

whenBound

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

Parameters:
stream - stream where to send result

isBound

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

Returns:
true if bound already

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