Java 9 introduces responsive flow under the java.util.concurrent.Flow package to support interoperable Publish-Subscribe Framework. It handles asynchronous data streams across asynchronous boundaries (passing elements to another thread or thread pool), and the receiver is not forced to buffer any amount of data, so buffer overflows cannot occur.
Flow API contains four interrelated core interfaces: Publisher, Subscriber, Subscribe and processor.<strong>@FunctionalInterface </strong>public static interface <strong>Publisher<T></strong> { public void <strong>subscribe</strong>(<strong>Subscriber</strong><? super T><!--? super T--> subscriber) } public static interface <strong>Subscriber<T></strong> { public void <strong>onSubscribe</strong>(Subscription subscription); public void <strong>onNext</strong>(T item); public void <strong>onError</strong>(Throwable throwable); public void <strong>onComplete</strong>(); } public static interface <strong>Subscription </strong>{ public void <strong>request</strong>(long n); public void <strong>cancel</strong>(); } public static interface <strong>Processor<T, R> </strong>extends <strong>Subscriber<T></strong>, <strong>Publisher<R></strong> { }
These four interfaces: Flow.Publisher, Flow.Processor, Flow.Subscriber and Flow. Subscriptions related to reactive streams specifications. Publisher interface has subscribe() method, subscription has cancel() and request() methods, Subscribers have onSubscribe(), onNext(), onError() and >onComplete() methods . Processorinterface implements all methods of Flow. Publisher and Flow.Subscriber interfaces.
The above is the detailed content of What is the core interface of Reactive Streams in Java 9?. For more information, please follow other related articles on the PHP Chinese website!