groovyx.gpars.dataflow
Interface DataflowReadChannel<T>

All Known Subinterfaces:
DataflowChannel<T>
All Known Implementing Classes:
DataflowComplexExpression, DataflowExpression, DataflowExpression.TransformMany, DataflowExpression.TransformOne, DataflowGetPropertyExpression, DataflowInvocationExpression, DataflowQueue, DataflowStreamReadAdapter, DataflowVariable, DataflowVariable.RemoteDataflowVariable, RemoteDataflowExpression

public interface DataflowReadChannel<T>

A common interface for all dataflow variables, streams or queues

Author:
Vaclav Pech Date: 21st Sep 2010

Method Summary
 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
 DataflowExpression<T> poll()
          Retrieves the value at the head of the buffer.
 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.
 void wheneverBound(groovy.lang.Closure closure)
          Send all pieces of data bound in the future to the provided stream when it becomes available *
 void wheneverBound(MessageStream stream)
          Send all pieces of data bound in the future to the provided stream when it becomes available
 

Method Detail

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

wheneverBound

void wheneverBound(groovy.lang.Closure closure)
Send all pieces of data bound in the future to the provided stream when it becomes available *

Parameters:
closure - closure to execute when data available

wheneverBound

void wheneverBound(MessageStream stream)
Send all pieces of data bound in the future to the 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

poll

DataflowExpression<T> poll()
                           throws java.lang.InterruptedException
Retrieves the value at the head of the buffer. Returns null, if no value is available.

Returns:
The value bound to the DFV at the head of the stream or null
Throws:
java.lang.InterruptedException - If the current thread is interrupted

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