GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 2.x: Add MulticastProcessor by akarnokd · Pull Request #6002 · ReactiveX/RxJava

Conversation

@akarnokd

@akarnokd akarnokd commented May 9, 2018

Copy link
Copy Markdown
Member

This PR adds the MulticastProcessor from the extensions project to be a standard processor option.

This type of processor fills the gap of having a backpressure-coordinating processor type as PublishProcessor doesn't coordinate backpressure on its own and Flowable.publish() often can't be used because the upstream may not yet exist when the dowstream consumers are setup.

MulticastProcessor

Example:

MulticastProcessor<Integer> mp = Flowable.range(1, 10)
    .subscribeWith(MulticastProcessor.create());

mp.test().assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

// --------------------

MulticastProcessor<Integer> mp2 = MulticastProcessor.create(4);
mp2.start();

assertTrue(mp2.offer(1));
assertTrue(mp2.offer(2));
assertTrue(mp2.offer(3));
assertTrue(mp2.offer(4));

assertFalse(mp2.offer(5));

mp2.onComplete();

mp2.test().assertResult(1, 2, 3, 4);

Resolves: #5999

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@akarnokd
2.x: Add MulticastProcessor
b204fc8
@akarnokd akarnokd added Enhancement 2.x labels May 9, 2018
@akarnokd akarnokd added this to the 2.2 milestone May 9, 2018
@codecov

codecov Bot commented May 9, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #6002 into 2.x will increase coverage by 0.01%.
The diff coverage is 98.67%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6002      +/-   ##
============================================
+ Coverage     98.25%   98.27%   +0.01%     
- Complexity     6062     6158      +96     
============================================
  Files           656      659       +3     
  Lines         44101    44514     +413     
  Branches       6118     6201      +83     
============================================
+ Hits          43333    43745     +412     
- Misses          230      231       +1     
  Partials        538      538
Impacted Files Coverage Δ Complexity Δ
...va/io/reactivex/processors/MulticastProcessor.java 98.67% <98.67%> (ø) 84 <84> (?)
...l/operators/observable/ObservableFlatMapMaybe.java 85.62% <0%> (-4.58%) 2% <0%> (ø)
...tivex/internal/observers/FutureSingleObserver.java 94.33% <0%> (-3.78%) 24% <0%> (-1%)
.../operators/observable/ObservableFlatMapSingle.java 88.8% <0%> (-3.74%) 2% <0%> (ø)
...rnal/operators/flowable/FlowableSkipLastTimed.java 95.91% <0%> (-2.05%) 2% <0%> (ø)
...nternal/operators/parallel/ParallelReduceFull.java 93.06% <0%> (-1.99%) 2% <0%> (ø)
...perators/single/SingleFlatMapIterableFlowable.java 96.66% <0%> (-1.67%) 2% <0%> (ø)
...rnal/subscriptions/DeferredScalarSubscription.java 98.46% <0%> (-1.54%) 28% <0%> (-1%)
...a/io/reactivex/internal/util/QueueDrainHelper.java 98.61% <0%> (-1.39%) 57% <0%> (-1%)
.../operators/mixed/FlowableSwitchMapCompletable.java 98.94% <0%> (-1.06%) 2% <0%> (ø)
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cedfc53...8f484aa. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akarnokd
Improve coverage, fix NPE before upstream arrives
65cc3ec
vanniktech
vanniktech approved these changes May 17, 2018
View reviewed changes

@vanniktech vanniktech left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I missed this PR

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java Outdated
* upstream when all {@link Subscriber}s have cancelled. Late {@code Subscriber}s will then be
* immediately completed.
* <p>
* Because of {@code MulticastProcessor} implements the {@link Subscriber} interface, calling

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd nuke the of here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java Outdated
* {@code onSubscribe} is mandatory (<a href="https://github.com/reactive-streams/reactive-streams-jvm#2.12">Rule 2.12</a>).
* If {@code MulticastProcessor} shoud run standalone, i.e., without subscribing the {@code MulticastProcessor} to another {@link Publisher},
* use {@link #start()} or {@link #startUnbounded()} methods to initialize the internal buffer.
* Failing to do so will lead to {@link NullPointerException} at runtime.

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lead to a

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java
public static <T> MulticastProcessor<T> create() {
return new MulticastProcessor<T>(bufferSize(), false);
}

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double new line

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java
* @param <T> the input and output value type
* @return the new MulticastProcessor instance
*/
public static <T> MulticastProcessor<T> create(int bufferSize) {

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add the @CheckReturnValue annotation here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java
* is cancelled
* @return the new MulticastProcessor instance
*/
public static <T> MulticastProcessor<T> create(boolean refCount) {

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add the @CheckReturnValue annotation here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java
* @param <T> the input and output value type
* @return the new MulticastProcessor instance
*/
public static <T> MulticastProcessor<T> create(int bufferSize, boolean refCount) {

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add the @CheckReturnValue annotation here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java
}

/**
* Constructs a fresh instance with the given prefetch amount and the optional

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no real need of having the documentation here, is there? It's not a public method and the create method already cover everything

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@akarnokd akarnokd May 17, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may help those who dig into the source code for some reason (learning, debugging, etc.). I'll leave it there.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/io/reactivex/processors/MulticastProcessor.java Outdated
@Override
public void onError(Throwable t) {
if (t == null) {
throw new NullPointerException("t is null");

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we also have another second sentence that was stating that nulls are not allowed per definition?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/io/reactivex/processors/MulticastProcessorTest.java

mp.test().assertResult();
}

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double new line

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@akarnokd akarnokd May 17, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, removed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/io/reactivex/processors/MulticastProcessorTest.java Outdated
.assertEmpty()
.requestMore(1)
.assertValues(0)
.assertNotComplete()

@vanniktech vanniktech May 17, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just use assertValuesOnly and then save the assertNotComplete call?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@akarnokd
Address review feedback.
8f484aa
vanniktech
vanniktech approved these changes May 17, 2018
View reviewed changes
@akarnokd
akarnokd merged commit f87879d into ReactiveX:2.x May 17, 2018
@akarnokd
akarnokd deleted the MulticastProcessor branch May 17, 2018 21:17
@akarnokd akarnokd mentioned this pull request May 17, 2018
2.1.14 release preparations #6009
Closed
@jared-bot jared-bot mentioned this pull request May 23, 2018
Dependency update: RxJava xmartlabs/bigbang-template#95
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@vanniktech vanniktech vanniktech approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

2.x Enhancement

Projects

None yet

Milestone

2.2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@akarnokd @vanniktech
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.