Skip to content
Albert Bifet edited this page Oct 17, 2013 · 3 revisions

A stream is a physical unit of SAMOA topology which connects different PIs with each other. As a reminder, Processors are wrapped in PIs to enable them to connect with other elements of the topology. Stream is also created by a TopologyBuilder just like a PI. A stream can have a single source but many destinations. A PI which is the source of a stream, owns the stream.

###1. Creating a Stream Following code snippet shows how a Stream is created:

builder.initTopology("Parma Topology");
Processor sourceProcessor = new Sampler();
ProcessingItem sourcePI = builder.createPI(samplerProcessor,3);
Stream sourceDataStream = builder.createStream(sourcePi);

###2. Connecting a Stream As described above, a Stream can have many destinations. In the following figure, a single stream from sourcePI is connected to three different destination PIs each having three instances.

not found

SAMOA supports three different ways of distribution of messages to multiple instances of a PI. ####2.1 Shuffle In this way of message distribution, messages/events are distributed randomly among various instances of a PI. Following figure shows how the messages are distributed.

Following code snipped shows how to connect a stream to a destination using random shuffling.

destinatinoPi.connectInputShuffleStream(sourceDataStream);

####2.2 Key In this way of message distribution, messages with same key are sent to same instance of a PI. Following figure illustrates key-based distribution.

Following code snippet shows how to connect a stream to a destination using key-based distribution.

destinatinoPi.connectInputKeyStream(sourceDataStream);

####2.3 All In this way of message distribution, all messages of a stream are sent to all instances of a destination PI. Following figure illustrates this distribution process.

Following code snippet shows how to connect a stream to a destination using All-based distribution.

destinatinoPi.connectInputAllStream(sourceDataStream);