Class Buffered<T,R>

java.lang.Object
net.pincette.rs.ProcessorBase<T,R>
net.pincette.rs.Buffered<T,R>
Type Parameters:
T - the incoming value type.
R - the outgoing value type.
All Implemented Interfaces:
Flow.Processor<T,R>, Flow.Publisher<R>, Flow.Subscriber<T>
Direct Known Subclasses:
Buffer, Encode, FlattenList, Per

public abstract class Buffered<T,R> extends ProcessorBase<T,R>
Base class for buffered processors. It uses a shared thread.
Since:
3.0
Author:
Werner Donnè
  • Constructor Details

    • Buffered

      protected Buffered(int requestSize)
      Create a buffered processor.
      Parameters:
      requestSize - the number of elements that will be requested from the upstream.
  • Method Details

    • addValues

      protected void addValues(List<R> values)
    • dispatch

      protected void dispatch(Runnable action)
    • emit

      protected void emit(long number)
      Specified by:
      emit in class ProcessorBase<T,R>
    • emit

      protected void emit()
      Triggers the downstream emission flow. The onNextAction method could use this.
    • getRequested

      protected long getRequested()
      Returns the number of requested elements by the downstream.
      Returns:
      The requested elements number.
    • isCompleted

      protected boolean isCompleted()
      Indicates whether the stream is completed.
      Returns:
      The completes status.
    • last

      protected void last()
      This is called when the stream has completed. It provides subclasses with the opportunity to flush any remaining data to the buffer.
    • onComplete

      public void onComplete()
      Specified by:
      onComplete in interface Flow.Subscriber<T>
      Overrides:
      onComplete in class ProcessorBase<T,R>
    • onError

      public void onError(Throwable t)
      Specified by:
      onError in interface Flow.Subscriber<T>
      Overrides:
      onError in class ProcessorBase<T,R>
    • onNext

      public void onNext(T value)
    • onNextAction

      protected abstract boolean onNextAction(T value)
      The onNext method uses this method.
      Parameters:
      value - the received value.
    • onSubscribe

      public void onSubscribe(Flow.Subscription subscription)
      Specified by:
      onSubscribe in interface Flow.Subscriber<T>
      Overrides:
      onSubscribe in class ProcessorBase<T,R>