The second example - a news system
In the previous example, we used the SubmissionPublisher
class, so we didn't implement the Flow.Publisher
and the Flow.Subscription
interfaces. If the functionality provided by the SubmissionPublisher
doesn't fit our needs, we will have to implement our own publisher and subscription.
In this section, you will learn how to implement both interfaces to learn the specification of the reactive streams. We are going to implement a news system where each piece of news will be associated with a category. A subscriber will be subscribed to one or more categories and the publisher will only send a piece of news to each subscriber if it's subscribed to its category.
The News class
The first class we're going to implement is the News
class. This class represents each piece of news we're going to send from the publisher to the consumer. We're going to store three attributes:
- Thecategory attribute: An
int
value that stores the category of the news. It can take the values...