Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ServiceBus] Cache UpdateDispositionWorkItem Mono #22317

Merged
merged 4 commits into from
Jun 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private Mono<Void> updateDispositionInternal(String lockToken, DeliveryState del
sink.error(new AmqpException(false, "updateDisposition failed while dispatching to Reactor.",
error, handler.getErrorContext(receiver)));
}
});
}).cache().then(Mono.empty()); // cache because closeAsync use `when` to subscribe this Mono again.
Copy link
Member

Choose a reason for hiding this comment

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

Do we need .then(Mono.empty())? If so, then use then()?

Copy link
Contributor Author

@YijunXieMS YijunXieMS Jun 22, 2021

Choose a reason for hiding this comment

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

Good catch. Mono.empty() is not required here.


workItem.setMono(result);

Expand Down Expand Up @@ -362,7 +362,7 @@ private void cleanupWorkItems() {
});
}

private void completeWorkItem(String lockToken, Delivery delivery, MonoSink<Void> sink, Throwable error) {
private void completeWorkItem(String lockToken, Delivery delivery, MonoSink<Object> sink, Throwable error) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need it to be a MonoSink of Object? I thought you could cache to .<Void>cache()?

Copy link
Contributor Author

@YijunXieMS YijunXieMS Jun 22, 2021

Choose a reason for hiding this comment

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

the .cache() call turns the sink into a MonoSink<Object> from MonoSink<Void>.

final Mono<Void> result = Mono.create(sink -> {
            workItem.start(sink);
            try {
                provider.getReactorDispatcher().invoke(() -> {
                    unsettled.disposition(deliveryState);
                    pendingUpdates.put(lockToken, workItem);
                });
            } catch (IOException error) {
                sink.error(new AmqpException(false, "updateDisposition failed while dispatching to Reactor.",
                    error, handler.getErrorContext(receiver)));
            }
        }).cache().then();

Copy link
Member

Choose a reason for hiding this comment

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

You can cast the create operator to Void as shown below.

final Mono<Void> result = Mono.<Void>create(sink -> {
            workItem.start(sink);
            try {
                provider.getReactorDispatcher().invoke(() -> {
                    unsettled.disposition(deliveryState);
                    pendingUpdates.put(lockToken, workItem);
                });
            } catch (IOException error) {
                sink.error(new AmqpException(false, "updateDisposition failed while dispatching to Reactor.",
                    error, handler.getErrorContext(receiver)));
            }
        }).cache();

final boolean isSettled = delivery != null && delivery.remotelySettled();
if (isSettled) {
delivery.settle();
Expand Down Expand Up @@ -392,7 +392,7 @@ private static final class UpdateDispositionWorkItem {

private Mono<Void> mono;
private Instant expirationTime;
private MonoSink<Void> sink;
private MonoSink<Object> sink;
private Throwable throwable;

private UpdateDispositionWorkItem(String lockToken, DeliveryState state, Duration timeout) {
Expand Down Expand Up @@ -429,11 +429,11 @@ private Mono<Void> getMono() {
return mono;
}

private MonoSink<Void> getSink() {
private MonoSink<Object> getSink() {
return sink;
}

private void start(MonoSink<Void> sink) {
private void start(MonoSink<Object> sink) {
Objects.requireNonNull(sink, "'sink' cannot be null.");
this.sink = sink;
this.sink.onDispose(() -> isDisposed.set(true));
Expand Down