Module mutiny.zero
Package mutiny.zero

Interface ZeroPublisher


  • public interface ZeroPublisher
    Factory methods to simplify the creation of reactive streams compliant Publisher.

    There are convenience methods for creating Publisher from in-memory data.

    The general-purpose abstraction is to use a Tube and the create(BackpressureStrategy, int, Consumer) factory method.

    • Method Summary

      All Methods Static Methods Deprecated Methods 
      Modifier and Type Method Description
      static <T> org.reactivestreams.Publisher<T> create​(BackpressureStrategy backpressureStrategy, int bufferSize, java.util.function.Consumer<Tube<T>> tubeConsumer)
      Deprecated.
      static <T> org.reactivestreams.Publisher<T> create​(TubeConfiguration configuration, java.util.function.Consumer<Tube<T>> tubeConsumer)
      Create a new Publisher with the general-purpose Tube API.
      static <T> org.reactivestreams.Publisher<T> empty()
      Create an empty Publisher that completes upon subscription without ever sending any item.
      static <T> org.reactivestreams.Publisher<T> fromCompletionStage​(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier)
      Create a Publisher from a CompletionStage.
      static <T> org.reactivestreams.Publisher<T> fromFailure​(java.lang.Throwable failure)
      Create a Publisher from a known failure.
      static <S,​T>
      org.reactivestreams.Publisher<T>
      fromGenerator​(java.util.function.Supplier<S> stateSupplier, java.util.function.Function<S,​java.util.Iterator<T>> generator)
      Create a Publisher from a generator over some state.
      static <T> org.reactivestreams.Publisher<T> fromItems​(T... items)
      Create a Publisher from existing items.
      static <T> org.reactivestreams.Publisher<T> fromIterable​(java.lang.Iterable<T> iterable)
      Create a Publisher from an iterable object.
      static <T> org.reactivestreams.Publisher<T> fromStream​(java.util.function.Supplier<java.util.stream.Stream<T>> supplier)
      Create a Publisher from a Stream.
      static <T> java.util.concurrent.CompletionStage<java.util.Optional<T>> toCompletionStage​(org.reactivestreams.Publisher<T> publisher)
      Create a CompletionStage from a Publisher.
    • Method Detail

      • fromItems

        @SafeVarargs
        static <T> org.reactivestreams.Publisher<T> fromItems​(T... items)
        Create a Publisher from existing items.
        Type Parameters:
        T - the items type
        Parameters:
        items - the existing items, cannot be a null array
        Returns:
        a new Publisher
      • fromIterable

        static <T> org.reactivestreams.Publisher<T> fromIterable​(java.lang.Iterable<T> iterable)
        Create a Publisher from an iterable object.

        Note that this assumes an in-memory, non-blocking Iterator. Do not try to force an iterator as a way to bridge an API with Publisher if it is does not behave like an in-memory data structure.

        Type Parameters:
        T - the items type
        Parameters:
        iterable - the iterable object, cannot be null
        Returns:
        a nes Publisher
      • fromStream

        static <T> org.reactivestreams.Publisher<T> fromStream​(java.util.function.Supplier<java.util.stream.Stream<T>> supplier)
        Create a Publisher from a Stream.

        Note that this assumes an in-memory, non-blocking data structure, just like fromIterable(Iterable). Also note that a Stream can only be traversed once, hence the use of a supplier because multiple subscriptions would fail.

        Type Parameters:
        T - the items type
        Parameters:
        supplier - the stream supplier, cannot be null
        Returns:
        a new Publisher
      • fromGenerator

        static <S,​T> org.reactivestreams.Publisher<T> fromGenerator​(java.util.function.Supplier<S> stateSupplier,
                                                                          java.util.function.Function<S,​java.util.Iterator<T>> generator)
        Create a Publisher from a generator over some state.

        Note that this assumes an in-memory, non-blocking data structure, just like fromIterable(Iterable).

        Type Parameters:
        S - the initial state type
        T - the items type
        Parameters:
        stateSupplier - the initial state supplier, cannot be null but can supply null
        generator - a generator function over the initial state and an iterator, cannot be null, cannot yield null
        Returns:
        a new Publisher
      • fromCompletionStage

        static <T> org.reactivestreams.Publisher<T> fromCompletionStage​(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier)
        Create a Publisher from a CompletionStage.
        Type Parameters:
        T - the item type
        Parameters:
        completionStageSupplier - the completion stage supplier, cannot be null, cannot yield null
        Returns:
        a new Publisher
      • toCompletionStage

        static <T> java.util.concurrent.CompletionStage<java.util.Optional<T>> toCompletionStage​(org.reactivestreams.Publisher<T> publisher)
        Create a CompletionStage from a Publisher.

        The Publisher is requested exactly 1 element and the subscription is cancelled after it has been received.

        Type Parameters:
        T - the item type
        Parameters:
        publisher - the publisher, cannot be null
        Returns:
        a new CompletionStage
      • fromFailure

        static <T> org.reactivestreams.Publisher<T> fromFailure​(java.lang.Throwable failure)
        Create a Publisher from a known failure.
        Type Parameters:
        T - the items type
        Parameters:
        failure - the failure, cannot be null
        Returns:
        a new Publisher
      • empty

        static <T> org.reactivestreams.Publisher<T> empty()
        Create an empty Publisher that completes upon subscription without ever sending any item.
        Type Parameters:
        T - the items type
        Returns:
        a new Publisher
      • create

        static <T> org.reactivestreams.Publisher<T> create​(TubeConfiguration configuration,
                                                           java.util.function.Consumer<Tube<T>> tubeConsumer)
        Create a new Publisher with the general-purpose Tube API.
        Type Parameters:
        T - the items type
        Parameters:
        configuration - the tube configuration
        tubeConsumer - the tube consumer, cannot be null
        Returns:
        a new Publisher
      • create

        @Deprecated
        static <T> org.reactivestreams.Publisher<T> create​(BackpressureStrategy backpressureStrategy,
                                                           int bufferSize,
                                                           java.util.function.Consumer<Tube<T>> tubeConsumer)
        Deprecated.
        Create a new Publisher with the general-purpose Tube API.
        Type Parameters:
        T - the items type
        Parameters:
        backpressureStrategy - the back-pressure strategy, cannot be null
        bufferSize - the buffer size, must be strictly positive when backpressureStrategy is one of BackpressureStrategy.BUFFER and BackpressureStrategy.LATEST
        tubeConsumer - the tube consumer, cannot be null
        Returns:
        a new Publisher