Class FilteredStreamMessage<T,​U>

java.lang.Object
com.linecorp.armeria.common.stream.FilteredStreamMessage<T,​U>
All Implemented Interfaces:
StreamMessage<U>, org.reactivestreams.Publisher<U>
Direct Known Subclasses:
FilteredHttpRequest, FilteredHttpResponse

public abstract class FilteredStreamMessage<T,​U> extends Object implements StreamMessage<U>
A StreamMessage that filters objects as they are published. The filtering will happen from an I/O thread, meaning the order of the filtering will match the order that the delegate processes the objects in.
  • Constructor Details

  • Method Details

    • filter

      protected abstract U filter(T obj)
      The filter to apply to published objects. The result of the filter is passed on to the delegate subscriber.
    • beforeSubscribe

      protected void beforeSubscribe(org.reactivestreams.Subscriber<? super U> subscriber, org.reactivestreams.Subscription subscription)
      A callback executed just before calling Subscriber.onSubscribe(Subscription) on subscriber. Override this method to execute any initialization logic that may be needed.
    • beforeComplete

      protected void beforeComplete(org.reactivestreams.Subscriber<? super U> subscriber)
      A callback executed just before calling Subscriber.onComplete() on subscriber. Override this method to execute any cleanup logic that may be needed before completing the subscription.
    • beforeError

      @Nullable protected @Nullable Throwable beforeError(org.reactivestreams.Subscriber<? super U> subscriber, Throwable cause)
      A callback executed just before calling Subscriber.onError(Throwable) on subscriber. Override this method to execute any cleanup logic that may be needed before failing the subscription. This method may rewrite the cause and then return a new one so that the new Throwable would be passed to Subscriber.onError(Throwable).
    • onCancellation

      protected void onCancellation(org.reactivestreams.Subscriber<? super U> subscriber)
      A callback executed when this StreamMessage is canceled by the Subscriber.
    • isOpen

      public final boolean isOpen()
      Description copied from interface: StreamMessage
      Returns true if this stream is not closed yet. Note that a stream may not be complete even if it's closed; a stream is complete when it's fully consumed by a Subscriber.
      Specified by:
      isOpen in interface StreamMessage<T>
    • isEmpty

      public final boolean isEmpty()
      Description copied from interface: StreamMessage
      Returns true if this stream has been closed and did not publish any elements. Note that this method will not return true when the stream is open even if it has not published anything so far, because it may publish something later.
      Specified by:
      isEmpty in interface StreamMessage<T>
    • demand

      public final long demand()
      Description copied from interface: StreamMessage
      Returns the current demand of this stream.
      Specified by:
      demand in interface StreamMessage<T>
    • whenComplete

      public final CompletableFuture<Void> whenComplete()
      Description copied from interface: StreamMessage
      Returns a CompletableFuture that completes when this stream is complete, either successfully or exceptionally, including cancellation and abortion.

      A StreamMessage is complete (or 'fully consumed') when:

      • the Subscriber consumes all elements and Subscriber.onComplete() is invoked,
      • an error occurred and Subscriber.onError(Throwable) is invoked,
      • the Subscription has been cancelled or
      • StreamMessage.abort() has been requested.
      Specified by:
      whenComplete in interface StreamMessage<T>
    • collect

      public CompletableFuture<List<U>> collect(EventExecutor executor, SubscriptionOption... options)
      Description copied from interface: StreamMessage
      Collects the elements published by this StreamMessage with the specified EventExecutor and SubscriptionOptions. The returned CompletableFuture will be notified when the elements are fully consumed.

      Note that if this StreamMessage was subscribed by other Subscriber already, the returned CompletableFuture will be completed with an IllegalStateException.

      Specified by:
      collect in interface StreamMessage<T>
    • subscribe

      public final void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, EventExecutor executor)
      Description copied from interface: StreamMessage
      Requests to start streaming data to the specified Subscriber. If there is a problem subscribing, Subscriber.onError(Throwable) will be invoked with one of the following exceptions:
      Specified by:
      subscribe in interface StreamMessage<T>
      executor - the executor to subscribe
    • subscribe

      public final void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, EventExecutor executor, SubscriptionOption... options)
      Description copied from interface: StreamMessage
      Requests to start streaming data to the specified Subscriber. If there is a problem subscribing, Subscriber.onError(Throwable) will be invoked with one of the following exceptions:
      Specified by:
      subscribe in interface StreamMessage<T>
      executor - the executor to subscribe
      options - SubscriptionOptions to subscribe with
    • defaultSubscriberExecutor

      public final EventExecutor defaultSubscriberExecutor()
      Description copied from interface: StreamMessage
      Returns the default EventExecutor which will be used when a user subscribes using StreamMessage.subscribe(Subscriber), StreamMessage.subscribe(Subscriber, SubscriptionOption...).

      Please note that if this method is called multiple times, the returned EventExecutors can be different depending on this StreamMessage implementation.

      Specified by:
      defaultSubscriberExecutor in interface StreamMessage<T>
    • abort

      public final void abort()
      Description copied from interface: StreamMessage
      Closes this stream with AbortedStreamException and prevents further subscription. A Subscriber that attempts to subscribe to an aborted stream will be notified with an AbortedStreamException via Subscriber.onError(Throwable). Calling this method on a closed or aborted stream has no effect.
      Specified by:
      abort in interface StreamMessage<T>
    • abort

      public final void abort(Throwable cause)
      Description copied from interface: StreamMessage
      Closes this stream with the specified Throwable and prevents further subscription. A Subscriber that attempts to subscribe to an aborted stream will be notified with the specified Throwable via Subscriber.onError(Throwable). Calling this method on a closed or aborted stream has no effect.
      Specified by:
      abort in interface StreamMessage<T>