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:
- The canceled attribute: A Boolean value that indicates if the subscription is cancelled or not
- The requested attribute: An AtomicLong value that stores the number of news items that have been requested by the consumer
- 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; ...