groovyx.gpars.dataflow.stream
Class DataflowStream<T>
java.lang.Object
groovyx.gpars.dataflow.stream.StreamCore<T>
groovyx.gpars.dataflow.stream.DataflowStream<T>
- Type Parameters:
T
- Type for values to pass through the stream
- All Implemented Interfaces:
- FList<T>, java.lang.Iterable<T>
public final class DataflowStream<T>
- extends StreamCore<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.
- Author:
- Johannes Link, Vaclav Pech
Method Summary |
protected StreamCore<T> |
createNewStream()
A factory method to create new instances of the correct class when needed |
FList<T> |
getRest()
Retrieves a DataflowStream representing the rest of this Stream after removing the first element |
java.lang.String |
toString()
|
Methods inherited from class groovyx.gpars.dataflow.stream.StreamCore |
addUpdateListener, appendingString, apply, decrementParties, eos, equals, filter, generate, getFirst, getFirstDFV, hashCode, incrementParties, isEmpty, iterator, leftShift, leftShift, map, reduce, reduce, wheneverBound, wheneverBound |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
DataflowStream
public DataflowStream()
- Creates an empty stream
DataflowStream
public DataflowStream(groovy.lang.Closure toBeApplied)
- Creates a stream while applying the supplied initialization closure to it
- Parameters:
toBeApplied
- The closure to use for initialization
DataflowStream
private DataflowStream(java.util.Collection<MessageStream> wheneverBoundListeners,
java.util.Collection<DataflowChannelListener<T>> updateListeners)
getRest
public FList<T> getRest()
- Retrieves a DataflowStream representing the rest of this Stream after removing the first element
- Specified by:
getRest
in interface FList<T>
- Specified by:
getRest
in class StreamCore<T>
- Returns:
- The remaining stream elements
createNewStream
protected StreamCore<T> createNewStream()
- A factory method to create new instances of the correct class when needed
- Specified by:
createNewStream
in class StreamCore<T>
- Returns:
- An instance of the appropriate sub-class
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object