|
org.codehaus.gpars | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovyx.gpars.dataflow.DataflowQueue
@SuppressWarnings({"ClassWithTooManyMethods"}) public final class DataflowQueue extends java.lang.Object
Represents a thread-safe data flow stream. Values or DataflowVariables are added using the '<<' operator and safely read once available using the 'val' property. The iterative methods like each(), collect(), iterator(), any(), all() or the for loops work with snapshots of the stream at the time of calling the particular method. For actors and Dataflow Operators the asynchronous non-blocking variants of the getValAsync() methods can be used. They register the request to read a value and will send a message to the actor or operator once the value is available.
Field Summary | |
---|---|
private java.util.concurrent.LinkedBlockingQueue |
queue
Stores the received DataflowVariables in the buffer. |
private java.lang.Object |
queueLock
Internal lock |
private java.util.Queue |
requests
Stores unsatisfied requests for values |
private java.util.Collection |
wheneverBoundListeners
A collection of listeners who need to be informed each time the stream is bound to a value |
Constructor Summary | |
DataflowQueue()
|
Method Summary | |
---|---|
void
|
bind(T value)
Adds a DataflowVariable representing the passed in value to the buffer. |
private DataflowVariable
|
copyDFV(java.util.Queue from, java.util.Queue to)
|
T
|
getVal()
Retrieves the value at the head of the buffer. |
T
|
getVal(long timeout, java.util.concurrent.TimeUnit units)
Retrieves the value at the head of the buffer. |
void
|
getValAsync(MessageStream callback)
Asynchronously retrieves the value at the head of the buffer. |
void
|
getValAsync(java.lang.Object attachment, MessageStream callback)
Asynchronously retrieves the value at the head of the buffer. |
private DataflowExpression
|
hookWheneverBoundListeners(DataflowExpression expr)
Hooks the registered when bound handlers to the supplied dataflow expression |
boolean
|
isBound()
Check if value has been set already for this expression |
java.util.Iterator
|
iterator()
Returns an iterator over a current snapshot of the buffer's content. |
DataflowWriteChannel
|
leftShift(DataflowReadChannel ref)
Adds a DataflowVariable to the buffer. |
DataflowWriteChannel
|
leftShift(T value)
Adds a DataflowVariable representing the passed in value to the buffer. |
int
|
length()
Returns the current size of the buffer |
DataflowExpression
|
poll()
Retrieves the value at the head of the buffer. |
private DataflowVariable
|
retrieveForBind()
Takes the first unsatisfied value request and binds a value on it. |
private DataflowVariable
|
retrieveOrCreateVariable()
Checks whether there's a DFV waiting in the queue and retrieves it. |
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 |
java.lang.String
|
toString()
|
void
|
whenBound(groovy.lang.Closure closure)
Schedule closure to be executed by pooled actor after the next 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)
|
void
|
whenBound(MessageStream stream)
Send the next bound piece of data to the provided stream when it becomes available |
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 |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Field Detail |
---|
private final java.util.concurrent.LinkedBlockingQueue queue
private final java.lang.Object queueLock
private final java.util.Queue requests
private final java.util.Collection wheneverBoundListeners
Constructor Detail |
---|
DataflowQueue()
Method Detail |
---|
@Override public void bind(T value)
value
- The value to bind to the head of the stream
private DataflowVariable copyDFV(java.util.Queue from, java.util.Queue to)
@Override public T getVal()
@Override public T getVal(long timeout, java.util.concurrent.TimeUnit units)
timeout
- The timeout valueunits
- Units for the timeout
@Override public void getValAsync(MessageStream callback)
callback
- The actor to notify when a value is bound
@Override public void getValAsync(java.lang.Object attachment, MessageStream callback)
attachment
- An arbitrary value to identify operator channels and so match requests and repliescallback
- The actor / operator to notify when a value is bound
private DataflowExpression hookWheneverBoundListeners(DataflowExpression expr)
expr
- The expression to hook all the when bound listeners to
@Override public boolean isBound()
public java.util.Iterator iterator()
@Override @SuppressWarnings("unchecked") public DataflowWriteChannel leftShift(DataflowReadChannel ref)
ref
- The DFV to add to the stream
@Override public DataflowWriteChannel leftShift(T value)
value
- The value to bind to the head of the stream
public int length()
@Override public DataflowExpression poll()
private DataflowVariable retrieveForBind()
private DataflowVariable retrieveOrCreateVariable()
@Override public void rightShift(groovy.lang.Closure closure)
closure
- closure to execute when data available
@Override public java.lang.String toString()
@Override public void whenBound(groovy.lang.Closure closure)
closure
- closure to execute when data available
@Override public void whenBound(Pool pool, groovy.lang.Closure closure)
pool
- The thread pool to use for task scheduling for asynchronous message deliveryclosure
- closure to execute when data available
@Override public void whenBound(PGroup group, groovy.lang.Closure closure)
@Override public void whenBound(MessageStream stream)
stream
- stream where to send result
@Override public void wheneverBound(groovy.lang.Closure closure)
closure
- closure to execute when data available
@Override public void wheneverBound(MessageStream stream)
stream
- stream where to send result
Copyright © 2008–2010 Václav Pech. All Rights Reserved.