All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.awscore.eventstream.DefaultEventStreamResponseHandlerBuilder Maven / Gradle / Ivy

Go to download

A single bundled dependency that includes all service and dependent JARs with third-party libraries relocated to different namespaces.

There is a newer version: 2.5.20
Show newest version
/*
 * Copyright 2010-2018 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.awscore.eventstream;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.reactivestreams.Subscriber;
import software.amazon.awssdk.annotations.SdkProtectedApi;
import software.amazon.awssdk.core.async.SdkPublisher;
import software.amazon.awssdk.utils.async.SequentialSubscriber;

/**
 * Base class for event stream response handler builders.
 *
 * @param  Type of POJO response.
 * @param  Type of event being published.
 * @param  Subtype of builder class for method chaining.
 */
@SdkProtectedApi
public abstract class DefaultEventStreamResponseHandlerBuilder
    implements EventStreamResponseHandler.Builder {

    private Consumer onResponse;
    private Consumer onError;
    private Runnable onComplete;
    private Supplier> subscriber;
    private Consumer> onSubscribe;
    private Function, SdkPublisher> publisherTransformer;

    protected DefaultEventStreamResponseHandlerBuilder() {
    }

    @Override
    public SubBuilderT onResponse(Consumer responseConsumer) {
        this.onResponse = responseConsumer;
        return subclass();
    }

    Consumer onResponse() {
        return onResponse;
    }

    @Override
    public SubBuilderT onError(Consumer consumer) {
        this.onError = consumer;
        return subclass();
    }

    Consumer onError() {
        return onError;
    }

    @Override
    public SubBuilderT onComplete(Runnable onComplete) {
        this.onComplete = onComplete;
        return subclass();
    }

    Runnable onComplete() {
        return onComplete;
    }

    @Override
    public SubBuilderT subscriber(Supplier> eventSubscriber) {
        this.subscriber = eventSubscriber;
        return subclass();
    }

    @Override
    public SubBuilderT subscriber(Consumer eventConsumer) {
        this.subscriber = () -> new SequentialSubscriber<>(eventConsumer, new CompletableFuture<>());
        return subclass();
    }

    Supplier> subscriber() {
        return subscriber;
    }

    @Override
    public SubBuilderT onEventStream(Consumer> onSubscribe) {
        this.onSubscribe = onSubscribe;
        return subclass();
    }

    Consumer> onEventStream() {
        return onSubscribe;
    }

    @Override
    public SubBuilderT publisherTransformer(Function, SdkPublisher> publisherTransformer) {
        this.publisherTransformer = publisherTransformer;
        return subclass();
    }

    Function, SdkPublisher> publisherTransformer() {
        return publisherTransformer;
    }

    private SubBuilderT subclass() {
        return (SubBuilderT) this;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy