
software.amazon.awssdk.services.bedrockruntime.model.ConverseStreamResponseHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bedrockruntime Show documentation
Show all versions of bedrockruntime Show documentation
The AWS Java SDK for Bedrock Runtime module holds the client classes that are used for
communicating with Bedrock Runtime.
/*
* 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.services.bedrockruntime.model;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.awscore.eventstream.EventStreamResponseHandler;
/**
* Response handler for the ConverseStream API.
*/
@Generated("software.amazon.awssdk:codegen")
@SdkPublicApi
public interface ConverseStreamResponseHandler extends EventStreamResponseHandler {
/**
* Create a {@link Builder}, used to create a {@link ConverseStreamResponseHandler}.
*/
static Builder builder() {
return new DefaultConverseStreamResponseHandlerBuilder();
}
/**
* Builder for {@link ConverseStreamResponseHandler}. This can be used to create the
* {@link ConverseStreamResponseHandler} in a more functional way, you may also directly implement the
* {@link ConverseStreamResponseHandler} interface if preferred.
*/
@Generated("software.amazon.awssdk:codegen")
interface Builder extends EventStreamResponseHandler.Builder {
/**
* Sets the subscriber to the {@link org.reactivestreams.Publisher} of events. The given {@link Visitor} will be
* called for each event received by the publisher. Events are requested sequentially after each event is
* processed. If you need more control over the backpressure strategy consider using
* {@link #subscriber(java.util.function.Supplier)} instead.
*
* @param visitor
* Visitor that will be invoked for each incoming event.
* @return This builder for method chaining
*/
Builder subscriber(Visitor visitor);
/**
* @return A {@link ConverseStreamResponseHandler} implementation that can be used in the ConverseStream API
* call.
*/
ConverseStreamResponseHandler build();
}
/**
* Visitor for subtypes of {@link ConverseStreamOutput}.
*/
@Generated("software.amazon.awssdk:codegen")
interface Visitor {
/**
* @return A new {@link Builder}.
*/
static Builder builder() {
return new DefaultConverseStreamVisitorBuilder();
}
/**
* A required "else" or "default" block, invoked when no other more-specific "visit" method is appropriate. This
* is invoked under two circumstances:
*
* - The event encountered is newer than the current version of the SDK, so no other more-specific "visit"
* method could be called. In this case, the provided event will be a generic {@link ConverseStreamOutput}.
* These events can be processed by upgrading the SDK.
* - The event is known by the SDK, but the "visit" was not overridden above. In this case, the provided event
* will be a specific type of {@link ConverseStreamOutput}.
*
*
* @param event
* The event that was not handled by a more-specific "visit" method.
*/
default void visitDefault(ConverseStreamOutput event) {
}
/**
* Invoked when a {@link MessageStartEvent} is encountered. If this is not overridden, the event will be given
* to {@link #visitDefault(ConverseStreamOutput)}.
*
* @param event
* Event being visited
*/
default void visitMessageStart(MessageStartEvent event) {
visitDefault(event);
}
/**
* Invoked when a {@link ContentBlockStartEvent} is encountered. If this is not overridden, the event will be
* given to {@link #visitDefault(ConverseStreamOutput)}.
*
* @param event
* Event being visited
*/
default void visitContentBlockStart(ContentBlockStartEvent event) {
visitDefault(event);
}
/**
* Invoked when a {@link ContentBlockDeltaEvent} is encountered. If this is not overridden, the event will be
* given to {@link #visitDefault(ConverseStreamOutput)}.
*
* @param event
* Event being visited
*/
default void visitContentBlockDelta(ContentBlockDeltaEvent event) {
visitDefault(event);
}
/**
* Invoked when a {@link ContentBlockStopEvent} is encountered. If this is not overridden, the event will be
* given to {@link #visitDefault(ConverseStreamOutput)}.
*
* @param event
* Event being visited
*/
default void visitContentBlockStop(ContentBlockStopEvent event) {
visitDefault(event);
}
/**
* Invoked when a {@link MessageStopEvent} is encountered. If this is not overridden, the event will be given to
* {@link #visitDefault(ConverseStreamOutput)}.
*
* @param event
* Event being visited
*/
default void visitMessageStop(MessageStopEvent event) {
visitDefault(event);
}
/**
* Invoked when a {@link ConverseStreamMetadataEvent} is encountered. If this is not overridden, the event will
* be given to {@link #visitDefault(ConverseStreamOutput)}.
*
* @param event
* Event being visited
*/
default void visitMetadata(ConverseStreamMetadataEvent event) {
visitDefault(event);
}
/**
* Builder for {@link Visitor}. The {@link Visitor} class may also be extended for a more traditional style but
* this builder allows for a more functional way of creating a visitor will callback methods.
*/
@Generated("software.amazon.awssdk:codegen")
interface Builder {
/**
* Callback to invoke when either an unknown event is visited or an unhandled event is visited.
*
* @param c
* Callback to process the event.
* @return This builder for method chaining.
*/
Builder onDefault(Consumer c);
/**
* @return Visitor implementation.
*/
Visitor build();
/**
* Callback to invoke when a {@link MessageStartEvent} is visited.
*
* @param c
* Callback to process the event.
* @return This builder for method chaining.
*/
Builder onMessageStart(Consumer c);
/**
* Callback to invoke when a {@link ContentBlockStartEvent} is visited.
*
* @param c
* Callback to process the event.
* @return This builder for method chaining.
*/
Builder onContentBlockStart(Consumer c);
/**
* Callback to invoke when a {@link ContentBlockDeltaEvent} is visited.
*
* @param c
* Callback to process the event.
* @return This builder for method chaining.
*/
Builder onContentBlockDelta(Consumer c);
/**
* Callback to invoke when a {@link ContentBlockStopEvent} is visited.
*
* @param c
* Callback to process the event.
* @return This builder for method chaining.
*/
Builder onContentBlockStop(Consumer c);
/**
* Callback to invoke when a {@link MessageStopEvent} is visited.
*
* @param c
* Callback to process the event.
* @return This builder for method chaining.
*/
Builder onMessageStop(Consumer c);
/**
* Callback to invoke when a {@link ConverseStreamMetadataEvent} is visited.
*
* @param c
* Callback to process the event.
* @return This builder for method chaining.
*/
Builder onMetadata(Consumer c);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy