Interface SdkPublisher<T>

    • Method Detail

      • adapt

        static <T> SdkPublisher<T> adapt​(org.reactivestreams.Publisher<T> toAdapt)
        Adapts a Publisher to SdkPublisher.
        Type Parameters:
        T - Type of object being published.
        Parameters:
        toAdapt - Publisher to adapt.
        Returns:
        SdkPublisher
      • filter

        default <U extends TSdkPublisher<U> filter​(Class<U> clzz)
        Filters published events to just those that are instances of the given class. This changes the type of publisher to the type specified in the Class.
        Type Parameters:
        U - Type of class to filter to.
        Parameters:
        clzz - Class to filter to. Includes subtypes of the class.
        Returns:
        New publisher, filtered to the given class.
      • filter

        default SdkPublisher<T> filter​(Predicate<T> predicate)
        Filters published events to just those that match the given predicate. Unlike filter(Class), this method does not change the type of the Publisher.
        Parameters:
        predicate - Predicate to match events.
        Returns:
        New publisher, filtered to just the events that match the predicate.
      • map

        default <U> SdkPublisher<U> map​(Function<T,​U> mapper)
        Perform a mapping on the published events. Returns a new publisher of the mapped events. Typically this method will change the type of the publisher.
        Type Parameters:
        U - Type being mapped to.
        Parameters:
        mapper - Mapping function to apply.
        Returns:
        New publisher with events mapped according to the given function.
      • flatMapIterable

        default <U> SdkPublisher<U> flatMapIterable​(Function<T,​Iterable<U>> mapper)
        Performs a mapping on the published events and creates a new publisher that emits the mapped events one by one.
        Type Parameters:
        U - Type of flattened event being mapped to.
        Parameters:
        mapper - Mapping function that produces an Iterable of new events to be flattened.
        Returns:
        New publisher of flattened events.
      • buffer

        default SdkPublisher<List<T>> buffer​(int bufferSize)
        Buffers the events into lists of the given buffer size. Note that the last batch of events may be less than the buffer size.
        Parameters:
        bufferSize - Number of events to buffer before delivering downstream.
        Returns:
        New publisher of buffered events.
      • limit

        default SdkPublisher<T> limit​(int limit)
        Limit the number of published events and cancel the subscription after that limit has been reached. The limit may never be reached if the downstream publisher doesn't have many events to publish. Once it reaches the limit, subsequent requests will be ignored.
        Parameters:
        limit - Number of events to publish.
        Returns:
        New publisher that will only publish up to the specified number of events.
      • addTrailingData

        default SdkPublisher<T> addTrailingData​(Supplier<Iterable<T>> trailingDataSupplier)
        Creates a new publisher that emits trailing events provided by trailingDataSupplier in addition to the published events.
        Parameters:
        trailingDataSupplier - supplier to provide the trailing data
        Returns:
        New publisher that will publish additional events
      • doAfterOnComplete

        default SdkPublisher<T> doAfterOnComplete​(Runnable afterOnComplete)
        Add a callback that will be invoked after this publisher invokes Subscriber.onComplete().
        Parameters:
        afterOnComplete - The logic that should be run immediately after onComplete.
        Returns:
        New publisher that invokes the requested callback.
      • doAfterOnError

        default SdkPublisher<T> doAfterOnError​(Consumer<Throwable> afterOnError)
        Add a callback that will be invoked after this publisher invokes Subscriber.onError(Throwable).
        Parameters:
        afterOnError - The logic that should be run immediately after onError.
        Returns:
        New publisher that invokes the requested callback.
      • doAfterOnCancel

        default SdkPublisher<T> doAfterOnCancel​(Runnable afterOnCancel)
        Add a callback that will be invoked after this publisher invokes Subscription.cancel().
        Parameters:
        afterOnCancel - The logic that should be run immediately after cancellation of the subscription.
        Returns:
        New publisher that invokes the requested callback.
      • subscribe

        default CompletableFuture<Void> subscribe​(Consumer<T> consumer)
        Subscribes to the publisher with the given Consumer. This consumer will be called for each event published. There is no backpressure using this method if the Consumer dispatches processing asynchronously. If more control over backpressure is required, consider using Publisher.subscribe(Subscriber).
        Parameters:
        consumer - Consumer to process event.
        Returns:
        CompletableFuture that will be notified when all events have been consumed or if an error occurs.