|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovyx.gpars.dataflow.stream.DataflowStream<T>
T
- Type for values to pass through the streampublic final class DataflowStream<T>
Represents a deterministic dataflow channel. Unlike a DataflowQueue, DataflowStream allows multiple readers each to read all the messages. Essentially, you may think of DataflowStream as a 1 to many communication channel, since when a reader consumes a messages, other readers will still be able to read the message. Also, all messages arrive to all readers in the same order. DataflowStream is implemented as a functional queue, which impacts the API in that users have to traverse the values in the stream themselves. On the other hand in offers handy methods for value filtering or transformation together with interesting performance characteristics. For convenience and for the ability to use DataflowStream with other dataflow constructs, like e.g. operators, you can wrap DataflowStreams with DataflowReadAdapter for read access or DataflowWriteAdapter for write access.
The DataflowStream class is designed for single-threaded producers and consumers. If multiple threads are supposed to read or write values to the stream, their access to the stream must be serialized externally or the adapters should be used.
Field Summary | |
---|---|
private DataflowVariable<T> |
first
|
private java.util.concurrent.atomic.AtomicReference<DataflowStream<T>> |
rest
|
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 | |
---|---|
|
DataflowStream()
Creates an empty stream |
|
DataflowStream(groovy.lang.Closure toBeApplied)
Creates a stream while applying the supplied initialization closure to it |
private |
DataflowStream(java.util.Collection<MessageStream> wheneverBoundListeners)
|
Method Summary | ||
---|---|---|
java.lang.String |
appendingString()
|
|
DataflowStream<T> |
apply(groovy.lang.Closure closure)
Calls the supplied closure with the stream as a parameter |
|
private void |
bind(T value)
|
|
static
|
eos()
|
|
boolean |
equals(java.lang.Object obj)
|
|
private static
|
eval(java.lang.Object valueOrDataflowVariable)
|
|
FList<T> |
filter(groovy.lang.Closure filterClosure)
Builds a filtered stream using the supplied filter closure |
|
private void |
filter(DataflowStream<T> rest,
groovy.lang.Closure filterClosure,
DataflowStream<T> result)
|
|
DataflowStream<T> |
generate(T seed,
groovy.lang.Closure generator,
groovy.lang.Closure condition)
Populates the stream with generated values |
|
private void |
generateNext(T value,
DataflowStream<T> stream,
groovy.lang.Closure generator,
groovy.lang.Closure condition)
|
|
T |
getFirst()
Retrieved the first element in the stream, blocking until a value is available |
|
(package private) DataflowVariable<T> |
getFirstDFV()
|
|
FList<T> |
getRest()
Retrieves a DataflowStream representing the rest of this Stream after removing the first element |
|
int |
hashCode()
|
|
private DataflowExpression<T> |
hookWheneverBoundListeners(DataflowExpression<T> expr)
Hooks the registered when bound handlers to the supplied dataflow expression |
|
boolean |
isEmpty()
Indicates, whether the first element in the stream is an eos |
|
java.util.Iterator<T> |
iterator()
Builds an iterator to iterate over the stream |
|
DataflowStream<T> |
leftShift(DataflowReadChannel<T> ref)
Adds a dataflow variable value to the stream, once the value is available |
|
DataflowStream<T> |
leftShift(T value)
Adds a value to the stream |
|
FList<java.lang.Object> |
map(groovy.lang.Closure mapClosure)
Builds a modified stream using the supplied map closure |
|
private void |
map(FList<T> rest,
groovy.lang.Closure mapClosure,
DataflowStream result)
|
|
T |
reduce(groovy.lang.Closure reduceClosure)
Reduces all elements in the stream using the supplied closure |
|
T |
reduce(T seed,
groovy.lang.Closure reduceClosure)
Reduces all elements in the stream using the supplied closure |
|
private T |
reduce(T current,
FList<T> rest,
groovy.lang.Closure reduceClosure)
|
|
java.lang.String |
toString()
|
|
void |
wheneverBound(groovy.lang.Closure closure)
|
|
void |
wheneverBound(MessageStream stream)
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final DataflowVariable<T> first
private final java.util.concurrent.atomic.AtomicReference<DataflowStream<T>> rest
private final java.util.Collection<MessageStream> wheneverBoundListeners
Constructor Detail |
---|
public DataflowStream()
public DataflowStream(groovy.lang.Closure toBeApplied)
toBeApplied
- The closure to use for initializationprivate DataflowStream(java.util.Collection<MessageStream> wheneverBoundListeners)
Method Detail |
---|
public static <T> T eos()
private static <T> T eval(java.lang.Object valueOrDataflowVariable)
public DataflowStream<T> generate(T seed, groovy.lang.Closure generator, groovy.lang.Closure condition)
seed
- The initial element to evaluate and add as the first value of the streamgenerator
- A closure generating stream elements from the previous valuescondition
- A closure indicating whether the generation should continue based on the last generated value
private void generateNext(T value, DataflowStream<T> stream, groovy.lang.Closure generator, groovy.lang.Closure condition)
public final DataflowStream<T> apply(groovy.lang.Closure closure)
closure
- The closure to call
public DataflowStream<T> leftShift(DataflowReadChannel<T> ref)
ref
- The DataflowVariable to check for value
public DataflowStream<T> leftShift(T value)
value
- The value to add
private void bind(T value)
DataflowVariable<T> getFirstDFV()
public T getFirst()
getFirst
in interface FList<T>
public FList<T> getRest()
getRest
in interface FList<T>
public boolean isEmpty()
isEmpty
in interface FList<T>
public FList<T> filter(groovy.lang.Closure filterClosure)
filter
in interface FList<T>
filterClosure
- The closure to decide on inclusion of elements
private void filter(DataflowStream<T> rest, groovy.lang.Closure filterClosure, DataflowStream<T> result)
public FList<java.lang.Object> map(groovy.lang.Closure mapClosure)
map
in interface FList<T>
mapClosure
- The closure to transform elements
private void map(FList<T> rest, groovy.lang.Closure mapClosure, DataflowStream result)
public T reduce(groovy.lang.Closure reduceClosure)
reduce
in interface FList<T>
reduceClosure
- The closure to reduce elements of the stream gradually into an accumulator. The accumulator is seeded with the first stream element.
public T reduce(T seed, groovy.lang.Closure reduceClosure)
reduce
in interface FList<T>
reduceClosure
- The closure to reduce elements of the stream gradually into an accumulator.seed
- The value to initialize the accumulator with.
private T reduce(T current, FList<T> rest, groovy.lang.Closure reduceClosure)
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String appendingString()
appendingString
in interface FList<T>
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void wheneverBound(groovy.lang.Closure closure)
public void wheneverBound(MessageStream stream)
private DataflowExpression<T> hookWheneverBoundListeners(DataflowExpression<T> expr)
expr
- The expression to hook all the when bound listeners to
|
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 |