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
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(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.

void whenBound(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(MessageStream stream)

Send the bound data to provided stream when it becomes available

 

Method Detail

get

@SuppressWarnings({"ProhibitedExceptionDeclared"})
public T 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 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.
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


getVal

public T getVal()
Reads the current value of the channel. Blocks, if the value has not been assigned yet.
throws:
InterruptedException If the current thread gets interrupted while waiting for the channel to be bound
Returns:
The actual value


getVal

public T getVal(long timeout, java.util.concurrent.TimeUnit units)
Reads the current value of the channel. Blocks up to given timeout, if the value has not been assigned yet.
throws:
InterruptedException If the current thread gets interrupted while waiting for the channel to be bound
Parameters:
timeout - The timeout value
units - Units for the timeout
Returns:
The actual value


getValAsync

public 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

public 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.


isBound

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


rightShift

public 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

public 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

public 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

public void whenBound(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

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–2010 Václav Pech. All Rights Reserved.