|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovyx.gpars.dataflow.DataflowQueue<T>
public final class DataflowQueue<T>
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<DataflowVariable<T>> |
queue
Stores the received DataflowVariables in the buffer. |
private java.lang.Object |
queueLock
Internal lock |
private java.util.Queue<DataflowVariable<T>> |
requests
Stores unsatisfied requests for values |
private java.util.Collection<MessageStream> |
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<T> |
copyDFV(java.util.Queue<DataflowVariable<T>> from,
java.util.Queue<DataflowVariable<T>> 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<T> |
hookWheneverBoundListeners(DataflowExpression<T> 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<T> |
iterator()
Returns an iterator over a current snapshot of the buffer's content. |
DataflowWriteChannel<T> |
leftShift(DataflowReadChannel<T> ref)
Adds a DataflowVariable to the buffer. |
DataflowWriteChannel<T> |
leftShift(T value)
Adds a DataflowVariable representing the passed in value to the buffer. |
int |
length()
Returns the current size of the buffer |
DataflowExpression<T> |
poll()
Retrieves the value at the head of the buffer. |
private DataflowVariable<T> |
retrieveForBind()
Takes the first unsatisfied value request and binds a value on it. |
private DataflowVariable<T> |
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(MessageStream stream)
Send the next bound piece of data to the 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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final java.lang.Object queueLock
private final java.util.concurrent.LinkedBlockingQueue<DataflowVariable<T>> queue
private final java.util.Queue<DataflowVariable<T>> requests
private final java.util.Collection<MessageStream> wheneverBoundListeners
Constructor Detail |
---|
public DataflowQueue()
Method Detail |
---|
public DataflowWriteChannel<T> leftShift(DataflowReadChannel<T> ref)
leftShift
in interface DataflowWriteChannel<T>
ref
- The DFV to add to the stream
public DataflowWriteChannel<T> leftShift(T value)
leftShift
in interface DataflowWriteChannel<T>
value
- The value to bind to the head of the stream
public void bind(T value)
bind
in interface DataflowWriteChannel<T>
value
- The value to bind to the head of the streamprivate DataflowExpression<T> hookWheneverBoundListeners(DataflowExpression<T> expr)
expr
- The expression to hook all the when bound listeners to
private DataflowVariable<T> retrieveForBind()
private DataflowVariable<T> copyDFV(java.util.Queue<DataflowVariable<T>> from, java.util.Queue<DataflowVariable<T>> to)
public T getVal() throws java.lang.InterruptedException
getVal
in interface DataflowReadChannel<T>
java.lang.InterruptedException
- If the current thread is interruptedpublic T getVal(long timeout, java.util.concurrent.TimeUnit units) throws java.lang.InterruptedException
getVal
in interface DataflowReadChannel<T>
timeout
- The timeout valueunits
- Units for the timeout
java.lang.InterruptedException
- If the current thread is interruptedpublic DataflowExpression<T> poll()
poll
in interface DataflowReadChannel<T>
public void getValAsync(MessageStream callback)
getValAsync
in interface DataflowReadChannel<T>
callback
- The actor to notify when a value is boundpublic void getValAsync(java.lang.Object attachment, MessageStream callback)
getValAsync
in interface DataflowReadChannel<T>
attachment
- An arbitrary value to identify operator channels and so match requests and repliescallback
- The actor / operator to notify when a value is boundpublic void rightShift(groovy.lang.Closure closure)
rightShift
in interface DataflowReadChannel<T>
closure
- closure to execute when data availablepublic void whenBound(groovy.lang.Closure closure)
whenBound
in interface DataflowReadChannel<T>
closure
- closure to execute when data availablepublic void whenBound(Pool pool, groovy.lang.Closure closure)
whenBound
in interface DataflowReadChannel<T>
pool
- The thread pool to use for task scheduling for asynchronous message deliveryclosure
- closure to execute when data availablepublic void whenBound(groovyx.gpars.group.PGroup group, groovy.lang.Closure closure)
DataflowReadChannel
whenBound
in interface DataflowReadChannel<T>
group
- The PGroup to use for task scheduling for asynchronous message deliveryclosure
- closure to execute when data availablepublic void whenBound(MessageStream stream)
whenBound
in interface DataflowReadChannel<T>
stream
- stream where to send resultpublic void wheneverBound(groovy.lang.Closure closure)
wheneverBound
in interface DataflowReadChannel<T>
closure
- closure to execute when data availablepublic void wheneverBound(MessageStream stream)
wheneverBound
in interface DataflowReadChannel<T>
stream
- stream where to send resultpublic boolean isBound()
isBound
in interface DataflowReadChannel<T>
private DataflowVariable<T> retrieveOrCreateVariable()
public int length()
public java.util.Iterator<T> iterator()
public java.lang.String toString()
toString
in class java.lang.Object
|
Copyright © 2008–2010 Václav Pech. All Rights Reserved. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |