Class PartitionHub<T>

    • Constructor Detail

      • PartitionHub

        public PartitionHub​(scala.Function0<scala.Function2<PartitionHub.ConsumerInfo,​T,​java.lang.Object>> partitioner,
                            int startAfterNrOfConsumers,
                            int bufferSize)
    • Method Detail

      • defaultBufferSize

        public static int defaultBufferSize()
        INTERNAL API
        Returns:
        (undocumented)
      • statefulSink

        public static <T> Sink<T,​Source<T,​NotUsed>> statefulSink​(scala.Function0<scala.Function2<PartitionHub.ConsumerInfo,​T,​java.lang.Object>> partitioner,
                                                                             int startAfterNrOfConsumers,
                                                                             int bufferSize)
        Creates a Sink that receives elements from its upstream producer and routes them to a dynamic set of consumers. After the Sink returned by this method is materialized, it returns a Source as materialized value. This Source can be materialized an arbitrary number of times and each materialization will receive the elements from the original Sink.

        Every new materialization of the Sink results in a new, independent hub, which materializes to its own Source for consuming the Sink of that materialization.

        If the original Sink is failed, then the failure is immediately propagated to all of its materialized Sources (possibly jumping over already buffered elements). If the original Sink is completed, then all corresponding Sources are completed. Both failure and normal completion is "remembered" and later materializations of the Source will see the same (failure or completion) state. Sources that are cancelled are simply removed from the dynamic set of consumers.

        This statefulSink should be used when there is a need to keep mutable state in the partition function, e.g. for implementing round-robin or sticky session kind of routing. If state is not needed the sink(scala.Function2<java.lang.Object, T, java.lang.Object>, int, int) can be more convenient to use.

        Parameters:
        partitioner - Function that decides where to route an element. It is a factory of a function to to be able to hold stateful variables that are unique for each materialization. The function takes two parameters; the first is information about active consumers, including an array of consumer identifiers and the second is the stream element. The function should return the selected consumer identifier for the given element. The function will never be called when there are no active consumers, i.e. there is always at least one element in the array of identifiers.
        startAfterNrOfConsumers - Elements are buffered until this number of consumers have been connected. This is only used initially when the operator is starting up, i.e. it is not honored when consumers have been removed (canceled).
        bufferSize - Total number of elements that can be buffered. If this buffer is full, the producer is backpressured.
        Returns:
        (undocumented)
      • statefulSink$default$3

        public static <T> int statefulSink$default$3()
      • sink

        public static <T> Sink<T,​Source<T,​NotUsed>> sink​(scala.Function2<java.lang.Object,​T,​java.lang.Object> partitioner,
                                                                     int startAfterNrOfConsumers,
                                                                     int bufferSize)
        Creates a Sink that receives elements from its upstream producer and routes them to a dynamic set of consumers. After the Sink returned by this method is materialized, it returns a Source as materialized value. This Source can be materialized an arbitrary number of times and each materialization will receive the elements from the original Sink.

        Every new materialization of the Sink results in a new, independent hub, which materializes to its own Source for consuming the Sink of that materialization.

        If the original Sink is failed, then the failure is immediately propagated to all of its materialized Sources (possibly jumping over already buffered elements). If the original Sink is completed, then all corresponding Sources are completed. Both failure and normal completion is "remembered" and later materializations of the Source will see the same (failure or completion) state. Sources that are cancelled are simply removed from the dynamic set of consumers.

        This sink should be used when the routing function is stateless, e.g. based on a hashed value of the elements. Otherwise the statefulSink(scala.Function0<scala.Function2<akka.stream.scaladsl.PartitionHub.ConsumerInfo, T, java.lang.Object>>, int, int) can be used to implement more advanced routing logic.

        Parameters:
        partitioner - Function that decides where to route an element. The function takes two parameters; the first is the number of active consumers and the second is the stream element. The function should return the index of the selected consumer for the given element, i.e. int greater than or equal to 0 and less than number of consumers. E.g. (size, elem) => math.abs(elem.hashCode % size). It's also possible to use -1 to drop the element.
        startAfterNrOfConsumers - Elements are buffered until this number of consumers have been connected. This is only used initially when the operator is starting up, i.e. it is not honored when consumers have been removed (canceled).
        bufferSize - Total number of elements that can be buffered. If this buffer is full, the producer is backpressured.
        Returns:
        (undocumented)
      • sink$default$3

        public static <T> int sink$default$3()
      • shape

        public SinkShape<T> shape()
        Description copied from interface: Graph
        The shape of a graph is all that is externally visible: its inlets and outlets.
        Returns:
        (undocumented)
      • createQueue

        public akka.stream.scaladsl.PartitionHub.Internal.PartitionQueue createQueue()