Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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 @@ -47,8 +47,6 @@ abstract class CancellableStreamMessage<T> extends AggregationSupport implements
static final Logger logger = LoggerFactory.getLogger(CancellableStreamMessage.class);

static final CloseEvent SUCCESSFUL_CLOSE = new CloseEvent(null);
static final CloseEvent CANCELLED_CLOSE = new CloseEvent(CancelledSubscriptionException.INSTANCE);
static final CloseEvent ABORTED_CLOSE = new CloseEvent(AbortedStreamException.INSTANCE);

private final CompletableFuture<Void> completionFuture = new EventLoopCheckingFuture<>();

Expand Down Expand Up @@ -134,17 +132,10 @@ final T prepareObjectForNotification(T o, boolean withPooledObjects) {
}

/**
* Returns newly created {@link CloseEvent} if the specified {@link Throwable} is not an instance of
* {@link CancelledSubscriptionException#INSTANCE} or {@link AbortedStreamException#INSTANCE}.
* Returns newly created {@link CloseEvent} with the cause.
*/
static CloseEvent newCloseEvent(Throwable cause) {
if (cause == CancelledSubscriptionException.INSTANCE) {
return CANCELLED_CLOSE;
} else if (cause == AbortedStreamException.INSTANCE) {
return ABORTED_CLOSE;
} else {
Comment on lines 141 to 145
Copy link
Contributor

Choose a reason for hiding this comment

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

As the stacktrace of cause is already empty, I think we can keep the original behavior.

return new CloseEvent(cause);
}
return new CloseEvent(cause);
}

static final class SubscriptionImpl implements Subscription {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ private void doRequest(long n) {
final void cancel() {
if (setState(State.OPEN, State.CLEANUP) || setState(State.CLOSED, State.CLEANUP)) {
// It the state was CLOSED, close() or close(cause) has been called before cancel() or abort()
// is called. We just ignore the previously pushed event and deal with CANCELLED_CLOSE.
// is called. We just ignore the previously pushed event and deal with cancelled close event.
final SubscriptionImpl subscription = this.subscription;
assert subscription != null;
notifySubscriberOfCloseEvent(subscription, CANCELLED_CLOSE);
notifySubscriberOfCloseEvent(subscription, new CloseEvent(CancelledSubscriptionException.get()));
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to use cached CloseEvent if CancelledSubscriptionException.get() returns CancelledSubscriptionException.INSTANCE.

Suggested change
notifySubscriberOfCloseEvent(subscription, new CloseEvent(CancelledSubscriptionException.get()));
notifySubscriberOfCloseEvent(subscription, newCloseEvent(CancelledSubscriptionException.get()));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! updated. 😉

}
}

Expand Down
Loading