-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue where event streams might fail with ClassCastException…
… or NoSuchElementException. (#2684) Fixed an issue where event streams might fail with ClassCastException or NoSuchElementException. This issue was caused by a race condition in EventStreamAsyncResponseTransformer. A simpler fix was done as part of #2678, but the entire class was overly-complex and difficult to understand. This change simplifies the transformer implementation to use SdkIterable's built-in methods.
- Loading branch information
Showing
14 changed files
with
774 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"type": "bugfix", | ||
"description": "Fixed an issue where event streams might fail with ClassCastException or NoSuchElementExceptions" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"type": "feature", | ||
"description": "Added new convenience methods to SdkPublisher: doAfterOnError, doAfterOnComplete, and doAfterCancel." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
473 changes: 129 additions & 344 deletions
473
.../java/software/amazon/awssdk/awscore/eventstream/EventStreamAsyncResponseTransformer.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
utils/src/main/java/software/amazon/awssdk/utils/async/EventListeningSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.utils.async; | ||
|
||
import java.util.function.Consumer; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
import software.amazon.awssdk.annotations.SdkProtectedApi; | ||
import software.amazon.awssdk.utils.Logger; | ||
|
||
/** | ||
* A {@link Subscriber} that can invoke callbacks during various parts of the subscriber and subscription lifecycle. | ||
*/ | ||
@SdkProtectedApi | ||
public final class EventListeningSubscriber<T> extends DelegatingSubscriber<T, T> { | ||
private static final Logger log = Logger.loggerFor(EventListeningSubscriber.class); | ||
|
||
private final Runnable afterCompleteListener; | ||
private final Consumer<Throwable> afterErrorListener; | ||
private final Runnable afterCancelListener; | ||
|
||
public EventListeningSubscriber(Subscriber<T> subscriber, | ||
Runnable afterCompleteListener, | ||
Consumer<Throwable> afterErrorListener, | ||
Runnable afterCancelListener) { | ||
super(subscriber); | ||
this.afterCompleteListener = afterCompleteListener; | ||
this.afterErrorListener = afterErrorListener; | ||
this.afterCancelListener = afterCancelListener; | ||
} | ||
|
||
@Override | ||
public void onNext(T t) { | ||
super.subscriber.onNext(t); | ||
} | ||
|
||
@Override | ||
public void onSubscribe(Subscription subscription) { | ||
super.onSubscribe(new CancelListeningSubscriber(subscription)); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable throwable) { | ||
super.onError(throwable); | ||
if (afterErrorListener != null) { | ||
callListener(() -> afterErrorListener.accept(throwable), | ||
"Post-onError callback failed. This exception will be dropped."); | ||
} | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
super.onComplete(); | ||
callListener(afterCompleteListener, "Post-onComplete callback failed. This exception will be dropped."); | ||
} | ||
|
||
private class CancelListeningSubscriber extends DelegatingSubscription { | ||
protected CancelListeningSubscriber(Subscription s) { | ||
super(s); | ||
} | ||
|
||
@Override | ||
public void cancel() { | ||
super.cancel(); | ||
callListener(afterCompleteListener, "Post-cancel callback failed. This exception will be dropped."); | ||
} | ||
} | ||
|
||
private void callListener(Runnable listener, String listenerFailureMessage) { | ||
if (listener != null) { | ||
try { | ||
listener.run(); | ||
} catch (RuntimeException e) { | ||
log.error(() -> listenerFailureMessage, e); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.