# SubmissionPublisher

Published articles for SubmissionPublisher.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Java 9 Flow API: arbitration and concatenation

DevFeed: [Java 9 Flow API: arbitration and concatenation](<https://devfeed.tech/articles/java-9-flow-api-arbitration-and-concatenation-24807.md>)

Original publisher: [Read original article](<https://akarnokd.blogspot.com/2017/09/java-9-flow-api-arbitration-and.html>)

Author: David Karnok (noreply@blogger.com)

Published: 2017-09-27T12:55:00Z

Content type: tutorial

Language: en

Sources: [Akarnokd - Advanced RxJava](<https://devfeed.tech/sources/akarnokd-advanced-rxjava.md>)

Topics: [Java 9](<https://devfeed.tech/topics/java-9.md>), [Java](<https://devfeed.tech/topics/java.md>), [API](<https://devfeed.tech/topics/api.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [arbiter](<https://devfeed.tech/tags/arbiter.md>), [arbitration](<https://devfeed.tech/tags/arbitration.md>), [concat](<https://devfeed.tech/tags/concat.md>), [concatenation](<https://devfeed.tech/tags/concatenation.md>), [concurrent](<https://devfeed.tech/tags/concurrent.md>), [event](<https://devfeed.tech/tags/event.md>), [flow](<https://devfeed.tech/tags/flow.md>), [flow-api](<https://devfeed.tech/tags/flow-api.md>), [java](<https://devfeed.tech/tags/java.md>), [java-9](<https://devfeed.tech/tags/java-9.md>), [jdk](<https://devfeed.tech/tags/jdk.md>), [onerrorresumenext](<https://devfeed.tech/tags/onerrorresumenext.md>), [publisher](<https://devfeed.tech/tags/publisher.md>), [repeat](<https://devfeed.tech/tags/repeat.md>), [request](<https://devfeed.tech/tags/request.md>), [retry](<https://devfeed.tech/tags/retry.md>), [submissionpublisher](<https://devfeed.tech/tags/submissionpublisher.md>), [subscriber](<https://devfeed.tech/tags/subscriber.md>), [subscription](<https://devfeed.tech/tags/subscription.md>), [subscriptionarbiter](<https://devfeed.tech/tags/subscriptionarbiter.md>)

### AI overview

This tutorial explains how to implement subscription arbitration for Java 9's Flow API when concatenating multiple publishers. It addresses stack growth, remaining-demand accounting, concurrent requests and cancellation, subscription switching, and produced-item tracking.

### Source excerpt

Introduction A very common task is to combine multiple sources, or more generally, start consuming a source once the previous source has terminated. The naive approach would be to simply call otherSource.subscribe(nextSubscriber) from onError or onComplete. Unfortunately, this doesn't work for two reasons: 1) it may end up with deep stacks due to a "tail" subscription from onError/onComplete and 2) we should request the remaining, unfulfilled amount from the new source that hasn't be provided by the previous source to not overflow the downstream. The first issue can be solved by applying a heavyweight observeOn in general and implementing a basic trampolining loop only for certain concrete cases such as flow concatenation to be described in this post. The second issue requires a more involved source: not only do we have to switch between Flow.Subscriptions from different sources, we have to make sure concurrent request() invocations are not lost and are routed to the proper Flow.Subscription along with any concurrent cancel() calls. Perhaps the difficulty is lessened by the fact that switching sources happens on a terminal event boundary only, thus we don't have to worry about the old source calling onNext while the logic switches to the new source and complicating the accounting of requested/emitted item counts. Enter SubscriptionArbiter. Subscription arbitration We have to deal with 4 types of potentially concurrent signals when arbitrating Flow.Subscriptions: A request(long) call from downstream that has to be routed to the current Flow.Subscription A cancel() call from downstream that has to be routed to the current Flow.Subscription and cancel any future Flow.Subscription. A setSubscription(Flow.Subscription) that is called by the current Flow.Subscriber after subscribing to any Flow.Publisher which is not guaranteed to happen on the same thread subscribe() is called (i.e., as with the standard SubmissionPublisher or our range() operator). A setProduced(long n)

## Java 9 Flow API: asynchronous integer range source

DevFeed: [Java 9 Flow API: asynchronous integer range source](<https://devfeed.tech/articles/java-9-flow-api-asynchronous-integer-range-source-24805.md>)

Original publisher: [Read original article](<https://akarnokd.blogspot.com/2017/03/java-9-flow-api-asynchronous-integer.html>)

Author: David Karnok (noreply@blogger.com)

Published: 2017-03-05T13:08:00Z

Content type: tutorial

Language: en

Sources: [Akarnokd - Advanced RxJava](<https://devfeed.tech/sources/akarnokd-advanced-rxjava.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Java 9](<https://devfeed.tech/topics/java-9.md>), [reactive](<https://devfeed.tech/topics/reactive.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [IntelliJ IDEA](<https://devfeed.tech/topics/intellij-idea.md>)

Tags: [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [backpressure](<https://devfeed.tech/tags/backpressure.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [flow](<https://devfeed.tech/tags/flow.md>), [flow-api](<https://devfeed.tech/tags/flow-api.md>), [java](<https://devfeed.tech/tags/java.md>), [java-9](<https://devfeed.tech/tags/java-9.md>), [jdk](<https://devfeed.tech/tags/jdk.md>), [operator](<https://devfeed.tech/tags/operator.md>), [publisher](<https://devfeed.tech/tags/publisher.md>), [range](<https://devfeed.tech/tags/range.md>), [reactive](<https://devfeed.tech/tags/reactive.md>), [reactive-streams](<https://devfeed.tech/tags/reactive-streams.md>), [request-management](<https://devfeed.tech/tags/request-management.md>), [source](<https://devfeed.tech/tags/source.md>), [submissionpublisher](<https://devfeed.tech/tags/submissionpublisher.md>), [subscriber](<https://devfeed.tech/tags/subscriber.md>), [subscription](<https://devfeed.tech/tags/subscription.md>), [trampoline](<https://devfeed.tech/tags/trampoline.md>), [varhandle](<https://devfeed.tech/tags/varhandle.md>)

### AI overview

A tutorial explores Java 9's Flow API and Reactive Streams interfaces by building an asynchronous integer range Publisher. It discusses composing Publishers, implementing Flow.Subscription, handling subscriber demand, and using IntelliJ 2017.1 EAP while the APIs were non-final.

### Source excerpt

Introduction Java 9 is becoming more reactive by introducing the Reactive-Streams interfaces under the parent class java.util.concurrent.Flow, enabling a new standard interoperation between future libraries built on top. There is almost no documentation beyond a underwhelming Oracle documentation and the SubmissionPublisher class' JavaDoc about how to write Publishers, Subscriptions and Subscribers under the Flow API. Plus the Oracle document practically concludes with see RxJava. Indeed, replacing the imports of org.reactivestreams.* with java.util.concurrent.Flow.* in RxJava 2's sources get's one a fully fledged reactive library but there seems to be one crucial expectation with components built on the Flow API: they have to be asynchronous at every stage. I could argue that the underlying concepts work totally fine in synchronous mode, but who am I to question the established definitions? Oh well, if the constraint is to be asynchronous, then let's do it in an asynchronous way. To see what it takes, we could start with a relatively simple source: an asynchronous integer range. Since both Java 9 and the IDE support is in non-final state, I recommend IntelliJ 2017.1 EAP for this "exercise". Asynchronous integer range source Unfortunately, Java 9 won't introduce any standard fluent API entry point with all the well loved map(), filter(), flatMap() etc. operators but one has to build individual Publishers and compose them stage-by-stage. This involves creating a parent Publisher class with the following typical pattern to host the input parameters of the flow to be observed: import java.util.concurrent.*; public final class FlowRange implements Flow.Publisher<Integer> { final int start; final int end; final Executor executor; public FlowRange(int start, int count, Executor executor) { this.start = start; this.end = start + count; this.executor = executor; } @Override public void subscribe(Flow.Subscriber<? super Integer> subscriber) { // TODO implement } } For brevit