The New Flow API
The Flow
class is part of the java.util.concurrent
package. It helps developers incorporate reactive programming in their applications. The class has one method, defaultBufferSize()
, and four interfaces.
The defaultBufferSize()
is a static method that returns the default buffer size for publishing and subscribing buffering. This default value is 256
and it is returned as an int
. Let's look at the four interfaces.
The Flow.Publisher interface
The Flow.Publisher
interface is a functional interface. A Publisher
is a producer of data sent to subscribers:
@FunctionalInterface public static interface Flow.Publisher<T>
This functional interface can serve as a lambda expression assignment target. It only takes one argument--the subscribed item type <T>
. It has one method:
void onSubscribe(Flow.Subscription subscription)
The Flow.Subscriber interface
The Flow.Subscriber
interface is used to receive messages and its implementation is shown here:
public static interface...