Reactive streams

Goal

  • Process a potentially unbounded number of elements
  • in sequences,
  • asynchronously passing elements between components,
  • with mandatory non-blocking back pressure.

Components

  • The API: specification.
  • The Technology Comparability Kit: is a test suit for conformance testing.

API Component

  • Publisher
  • Subscriber
  • Subscription
  • Processor

Publisher

Provider of a number of sequenced elements, publishing them according the demand received from its Subscriber

public interface Publisher<T> {
    public void subscribe(Subscriber<? super T> s);
}

Subscriber

public interface Subscriber<T> {
    public void onSubscrive(Subscription s);
    public void onNext(T t);
    public void onError(Throwable t);
    public void onComplete();
}

Subscription

It is shared by exactly one Publisher and one Subscriber for the purpose of mediating the data exchange between this pair.

public interface Subscription {
    public void request(long n);
    public void cancel();
}

Processor

A Processor represents a processing stage—which is both a Subscriber and a Publisher and MUST obey the contracts of both.

public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {
}

Subscriber controlled queue bounds

  • the total number of elements requested: P
  • the number of elements that have been processed: N
  • Then the maximum number of elements that may arrive (until more demand is signaled to the Publisher) is P - N.
  • In the case that the subscriber also knows the number of elements B in its input buffer then this bound can be refined to P - B - N.