The publisher classes

We need four classes to implement the Flow.Publisher and the Flow.Subscription interfaces. The first one is the MySubscription class that implements the Flow.Subscription interface. We are going to store three attributes in this class:

  1. The canceled attribute: A Boolean value that indicates if the subscription is cancelled or not
  2. The requested attribute: An AtomicLong value that stores the number of news items that have been requested by the consumer
  3. The categories attribute: A Set of Integer values that stores the categories of the news associated with this subscription

The following code shows the declaration of the attributes:

public class MySubscription implements Subscription { private boolean cancelled = false; ...

Get Mastering Concurrency Programming with Java 9 - Second Edition 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.