Sample implementation

In any given implementation of reactive programming, we will have a Subscriber that requests data and a Publisher that provides the data. Let's first look at a sample Subscriber implementation:

    import java.util.concurrent.Flow.*;    public class packtSubscriber<T> implements Subscriber<T>    {      private Subscription theSubscription;      // We will override the four Subscriber interface methods      @Override      public void onComplete()      {        System.out.println("Data stream ended");      }      @Override      public void onError(Throwable theError)      {        theError.printStackTrace();      }      @Override      public void onNext(T theItem)      {        System.out.println("Next item received: " + theItem);        theSubscription.request(19);  // arbitrary number for         example purposes      } @Override ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.