O'Reilly logo

Mastering Concurrency Programming with Java 9 - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required