Class MergeSequence

java.lang.Object
org.apache.pekko.stream.javadsl.MergeSequence

public class MergeSequence extends Object
Takes multiple streams whose elements in aggregate have a defined linear sequence with difference 1, starting at 0, and outputs a single stream containing these elements, in order. That is, given a set of input streams with combined elements *ek*:

*e0*, *e1*, *e2*, ..., *en*

This will output a stream ordered by *k*.

The elements in the input streams must already be sorted according to the sequence. The input streams do not need to be linear, but the aggregate stream must be linear, no element *k* may be skipped or duplicated, either of these conditions will cause the stream to fail.

The typical use case for this is to merge a partitioned stream back together while maintaining order. This can be achieved by first using zipWithIndex on the input stream, then partitioning using a Partition fanout, and then maintaining the index through the processing of each partition before bringing together with this stage.

'''Emits when''' one of the upstreams has the next expected element in the sequence available.

'''Backpressures when''' downstream backpressures

'''Completes when''' all upstreams complete

'''Cancels when''' downstream cancels

  • Constructor Details

    • MergeSequence

      public MergeSequence()
  • Method Details

    • create

      public static <T> Graph<UniformFanInShape<T,T>,NotUsed> create(Function<T,Object> extractSequence)
      Create a new anonymous MergeSequence operator with two input ports.

      Parameters:
      extractSequence - The function to extract the sequence from an element.
    • create

      public static <T> Graph<UniformFanInShape<T,T>,NotUsed> create(int inputCount, Function<T,Object> extractSequence)
      Create a new anonymous MergeSequence operator.

      Parameters:
      inputCount - The number of input streams.
      extractSequence - The function to extract the sequence from an element.
    • create

      public static <T> Graph<UniformFanInShape<T,T>,NotUsed> create(Class<T> clazz, int inputCount, Function<T,Object> extractSequence)
      Create a new anonymous Concat operator with the specified input types.

      Parameters:
      clazz - a type hint for this method
      inputCount - The number of input streams.
      extractSequence - The function to extract the sequence from an element.