1 package software.amazon.awssdk.services.json.model; 2 3 import java.util.function.Consumer; 4 import software.amazon.awssdk.annotations.Generated; 5 import software.amazon.awssdk.annotations.SdkPublicApi; 6 import software.amazon.awssdk.awscore.eventstream.EventStreamResponseHandler; 7 8 /** 9 * Response handler for the EventStreamOperation API. 10 */ 11 @Generated("software.amazon.awssdk:codegen") 12 @SdkPublicApi 13 public interface EventStreamOperationResponseHandler extends 14 EventStreamResponseHandler<EventStreamOperationResponse, EventStream> { 15 /** 16 * Create a {@link Builder}, used to create a {@link EventStreamOperationResponseHandler}. 17 */ builder()18 static Builder builder() { 19 return new DefaultEventStreamOperationResponseHandlerBuilder(); 20 } 21 22 /** 23 * Builder for {@link EventStreamOperationResponseHandler}. This can be used to create the 24 * {@link EventStreamOperationResponseHandler} in a more functional way, you may also directly implement the 25 * {@link EventStreamOperationResponseHandler} interface if preferred. 26 */ 27 @Generated("software.amazon.awssdk:codegen") 28 interface Builder extends EventStreamResponseHandler.Builder<EventStreamOperationResponse, EventStream, Builder> { 29 /** 30 * Sets the subscriber to the {@link org.reactivestreams.Publisher} of events. The given {@link Visitor} will be 31 * called for each event received by the publisher. Events are requested sequentially after each event is 32 * processed. If you need more control over the backpressure strategy consider using 33 * {@link #subscriber(java.util.function.Supplier)} instead. 34 * 35 * @param visitor 36 * Visitor that will be invoked for each incoming event. 37 * @return This builder for method chaining 38 */ subscriber(Visitor visitor)39 Builder subscriber(Visitor visitor); 40 41 /** 42 * @return A {@link EventStreamOperationResponseHandler} implementation that can be used in the 43 * EventStreamOperation API call. 44 */ build()45 EventStreamOperationResponseHandler build(); 46 } 47 48 /** 49 * Visitor for subtypes of {@link EventStream}. 50 */ 51 @Generated("software.amazon.awssdk:codegen") 52 interface Visitor { 53 /** 54 * @return A new {@link Builder}. 55 */ builder()56 static Builder builder() { 57 return new DefaultEventStreamOperationVisitorBuilder(); 58 } 59 60 /** 61 * A required "else" or "default" block, invoked when no other more-specific "visit" method is appropriate. This 62 * is invoked under two circumstances: 63 * <ol> 64 * <li>The event encountered is newer than the current version of the SDK, so no other more-specific "visit" 65 * method could be called. In this case, the provided event will be a generic {@link EventStream}. These events 66 * can be processed by upgrading the SDK.</li> 67 * <li>The event is known by the SDK, but the "visit" was not overridden above. In this case, the provided event 68 * will be a specific type of {@link EventStream}.</li> 69 * </ol> 70 * 71 * @param event 72 * The event that was not handled by a more-specific "visit" method. 73 */ visitDefault(EventStream event)74 default void visitDefault(EventStream event) { 75 } 76 77 /** 78 * Invoked when a {@link EventOne} is encountered. If this is not overridden, the event will be given to 79 * {@link #visitDefault(EventStream)}. 80 * 81 * @param event 82 * Event being visited 83 */ visit(EventOne event)84 default void visit(EventOne event) { 85 visitDefault(event); 86 } 87 88 /** 89 * Invoked when a {@link EventTwo} is encountered. If this is not overridden, the event will be given to 90 * {@link #visitDefault(EventStream)}. 91 * 92 * @param event 93 * Event being visited 94 */ visitEventTheSecond(EventTwo event)95 default void visitEventTheSecond(EventTwo event) { 96 visitDefault(event); 97 } 98 99 /** 100 * Invoked when a {@link EventOne} is encountered. If this is not overridden, the event will be given to 101 * {@link #visitDefault(EventStream)}. 102 * 103 * @param event 104 * Event being visited 105 */ visitSecondEventOne(EventOne event)106 default void visitSecondEventOne(EventOne event) { 107 visitDefault(event); 108 } 109 110 /** 111 * Invoked when a {@link LegacyEventThree} is encountered. If this is not overridden, the event will be given to 112 * {@link #visitDefault(EventStream)}. 113 * 114 * @param event 115 * Event being visited 116 */ visit(LegacyEventThree event)117 default void visit(LegacyEventThree event) { 118 visitDefault(event); 119 } 120 121 /** 122 * Builder for {@link Visitor}. The {@link Visitor} class may also be extended for a more traditional style but 123 * this builder allows for a more functional way of creating a visitor will callback methods. 124 */ 125 @Generated("software.amazon.awssdk:codegen") 126 interface Builder { 127 /** 128 * Callback to invoke when either an unknown event is visited or an unhandled event is visited. 129 * 130 * @param c 131 * Callback to process the event. 132 * @return This builder for method chaining. 133 */ onDefault(Consumer<EventStream> c)134 Builder onDefault(Consumer<EventStream> c); 135 136 /** 137 * @return Visitor implementation. 138 */ build()139 Visitor build(); 140 141 /** 142 * Callback to invoke when a {@link EventOne} is visited. 143 * 144 * @param c 145 * Callback to process the event. 146 * @return This builder for method chaining. 147 */ onEventOne(Consumer<EventOne> c)148 Builder onEventOne(Consumer<EventOne> c); 149 150 /** 151 * Callback to invoke when a {@link EventTwo} is visited. 152 * 153 * @param c 154 * Callback to process the event. 155 * @return This builder for method chaining. 156 */ onEventTheSecond(Consumer<EventTwo> c)157 Builder onEventTheSecond(Consumer<EventTwo> c); 158 159 /** 160 * Callback to invoke when a {@link EventOne} is visited. 161 * 162 * @param c 163 * Callback to process the event. 164 * @return This builder for method chaining. 165 */ onSecondEventOne(Consumer<EventOne> c)166 Builder onSecondEventOne(Consumer<EventOne> c); 167 168 /** 169 * Callback to invoke when a {@link LegacyEventThree} is visited. 170 * 171 * @param c 172 * Callback to process the event. 173 * @return This builder for method chaining. 174 */ onLegacyEventThree(Consumer<LegacyEventThree> c)175 Builder onLegacyEventThree(Consumer<LegacyEventThree> c); 176 } 177 } 178 } 179 180