Skip to content

Surface area review #4971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -33,10 +33,10 @@
public final class SplittingTransformerConfiguration implements ToCopyableBuilder<SplittingTransformerConfiguration.Builder,
SplittingTransformerConfiguration> {

private final Long bufferSize;
private final Long bufferSizeInBytes;

private SplittingTransformerConfiguration(DefaultBuilder builder) {
this.bufferSize = Validate.paramNotNull(builder.bufferSize, "bufferSize");
this.bufferSizeInBytes = Validate.paramNotNull(builder.bufferSize, "bufferSize");
}

/**
Expand All @@ -49,8 +49,8 @@ public static Builder builder() {
/**
* @return the buffer size
*/
public Long bufferSize() {
return bufferSize;
public Long bufferSizeInBytes() {
return bufferSizeInBytes;
}

@Override
Expand All @@ -64,12 +64,12 @@ public boolean equals(Object o) {

SplittingTransformerConfiguration that = (SplittingTransformerConfiguration) o;

return Objects.equals(bufferSize, that.bufferSize);
return Objects.equals(bufferSizeInBytes, that.bufferSizeInBytes);
}

@Override
public int hashCode() {
return bufferSize != null ? bufferSize.hashCode() : 0;
return bufferSizeInBytes != null ? bufferSizeInBytes.hashCode() : 0;
}

@Override
Expand All @@ -80,26 +80,26 @@ public Builder toBuilder() {
public interface Builder extends CopyableBuilder<Builder, SplittingTransformerConfiguration> {

/**
* Configures the buffer size of the {@link SplittingTransformer}.
* Configures the maximum amount of memory in bytes buffered by the {@link SplittingTransformer}.
*
* @param bufferSize the buffer size
* @param bufferSize the buffer size in bytes
* @return This object for method chaining.
*/
Builder bufferSize(Long bufferSize);
Builder bufferSizeInBytes(Long bufferSize);
}

private static final class DefaultBuilder implements Builder {
private Long bufferSize;

private DefaultBuilder(SplittingTransformerConfiguration configuration) {
this.bufferSize = configuration.bufferSize;
this.bufferSize = configuration.bufferSizeInBytes;
}

private DefaultBuilder() {
}

@Override
public Builder bufferSize(Long bufferSize) {
public Builder bufferSizeInBytes(Long bufferSize) {
this.bufferSize = bufferSize;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import software.amazon.awssdk.core.SdkResponse;
import software.amazon.awssdk.core.SplittingTransformerConfiguration;
import software.amazon.awssdk.core.internal.async.ByteArrayAsyncResponseTransformer;
import software.amazon.awssdk.core.internal.async.DefaultAsyncResponseTransformerSplitResult;
import software.amazon.awssdk.core.internal.async.FileAsyncResponseTransformer;
import software.amazon.awssdk.core.internal.async.InputStreamResponseTransformer;
import software.amazon.awssdk.core.internal.async.PublisherAsyncResponseTransformer;
import software.amazon.awssdk.core.internal.async.SplittingTransformer;
import software.amazon.awssdk.utils.Validate;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
* Callback interface to handle a streaming asynchronous response.
Expand Down Expand Up @@ -116,25 +119,26 @@ public interface AsyncResponseTransformer<ResponseT, ResultT> {
void exceptionOccurred(Throwable error);

/**
* Creates an {@link SplitAsyncResponseTransformer} which contains an {@link SplittingTransformer} that splits the
* Creates an {@link SplitResult} which contains an {@link SplittingTransformer} that splits the
* {@link AsyncResponseTransformer} into multiple ones, publishing them as a {@link SdkPublisher}.
*
* @param splitConfig configuration for the split transformer
* @return SplitAsyncResponseTransformer instance.
* @see SplittingTransformer
* @see SplitAsyncResponseTransformer
* @see SplitResult
*/
default SplitAsyncResponseTransformer<ResponseT, ResultT> split(SplittingTransformerConfiguration splitConfig) {
default SplitResult<ResponseT, ResultT> split(SplittingTransformerConfiguration splitConfig) {
Validate.notNull(splitConfig, "splitConfig must not be null");
CompletableFuture<ResultT> future = new CompletableFuture<>();
SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> transformer = SplittingTransformer
.<ResponseT, ResultT>builder()
.upstreamResponseTransformer(this)
.maximumBufferSize(splitConfig.bufferSize())
.returnFuture(future)
.maximumBufferSizeInBytes(splitConfig.bufferSizeInBytes())
.resultFuture(future)
.build();
return SplitAsyncResponseTransformer.<ResponseT, ResultT>builder()
.asyncResponseTransformerPublisher(transformer)
.future(future)
return AsyncResponseTransformer.SplitResult.<ResponseT, ResultT>builder()
.publisher(transformer)
.resultFuture(future)
.build();
}

Expand Down Expand Up @@ -285,4 +289,68 @@ static <ResponseT extends SdkResponse> AsyncResponseTransformer<ResponseT, Respo
AsyncResponseTransformer<ResponseT, ResponseInputStream<ResponseT>> toBlockingInputStream() {
return new InputStreamResponseTransformer<>();
}

/**
* Helper interface containing the result of {@link AsyncResponseTransformer#split(SplittingTransformerConfiguration)
* splitting} an AsyncResponseTransformer. This class holds both the publisher of the individual
* {@code AsyncResponseTransformer<ResponseT, ResponseT>} and the {@code CompletableFuture <ResultT>} which will
* complete when the {@code AsyncResponseTransformer} that was split itself would complete.
*
* @param <ResponseT> ResponseT of the original AsyncResponseTransformer that was split.
* @param <ResultT> ResultT of the original AsyncResponseTransformer that was split.
* @see AsyncResponseTransformer#split(SplittingTransformerConfiguration)
*/
interface SplitResult<ResponseT, ResultT>
extends ToCopyableBuilder<AsyncResponseTransformer.SplitResult.Builder<ResponseT, ResultT>,
AsyncResponseTransformer.SplitResult<ResponseT, ResultT>> {

/**
* The individual {@link AsyncResponseTransformer} will be available through the publisher returned by this method.
*
* @return the publisher which publishes the individual {@link AsyncResponseTransformer}
*/
SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher();

/**
* The future returned by this method will be completed when the future returned by calling the
* {@link AsyncResponseTransformer#prepare()} method on the AsyncResponseTransformer which was split completes.
*
* @return The future
*/
CompletableFuture<ResultT> resultFuture();

static <ResponseT, ResultT> Builder<ResponseT, ResultT> builder() {
return DefaultAsyncResponseTransformerSplitResult.builder();
}

interface Builder<ResponseT, ResultT>
extends CopyableBuilder<AsyncResponseTransformer.SplitResult.Builder<ResponseT, ResultT>,
AsyncResponseTransformer.SplitResult<ResponseT, ResultT>> {

/**
* @return the publisher which was configured on this Builder instance.
*/
SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher();

/**
* Sets the publisher publishing the individual {@link AsyncResponseTransformer}
* @param publisher the publisher
* @return an instance of this Builder
*/
Builder<ResponseT, ResultT> publisher(SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher);

/**
* @return The future which was configured an this Builder instance.
*/
CompletableFuture<ResultT> resultFuture();

/**
* Sets the future that will be completed when the future returned by calling the
* {@link AsyncResponseTransformer#prepare()} method on the AsyncResponseTransformer which was split completes.
* @param future the future
* @return an instance of this Builder
*/
Builder<ResponseT, ResultT> resultFuture(CompletableFuture<ResultT> future);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.core.internal.async;

import java.util.concurrent.CompletableFuture;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
import software.amazon.awssdk.core.async.SdkPublisher;
import software.amazon.awssdk.utils.Validate;

@SdkInternalApi
public final class DefaultAsyncResponseTransformerSplitResult<ResponseT, ResultT>
implements AsyncResponseTransformer.SplitResult<ResponseT, ResultT> {

private final SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher;
private final CompletableFuture<ResultT> future;

private DefaultAsyncResponseTransformerSplitResult(Builder<ResponseT, ResultT> builder) {
this.publisher = Validate.paramNotNull(
builder.publisher(), "asyncResponseTransformerPublisher");
this.future = Validate.paramNotNull(
builder.resultFuture(), "future");
}

/**
* The individual {@link AsyncResponseTransformer} will be available through the publisher returned by this method.
* @return the publisher which publishes the individual {@link AsyncResponseTransformer}
*/
public SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher() {
return this.publisher;
}

/**
* The future returned by this method will be completed when the future returned by calling the
* {@link AsyncResponseTransformer#prepare()} method on the AsyncResponseTransformer which was split completes.
* @return The future
*/
public CompletableFuture<ResultT> resultFuture() {
return this.future;
}

@Override
public AsyncResponseTransformer.SplitResult.Builder<ResponseT, ResultT> toBuilder() {
return new DefaultBuilder<>(this);
}

public static <ResponseT, ResultT> DefaultBuilder<ResponseT, ResultT> builder() {
return new DefaultBuilder<>();
}

public static class DefaultBuilder<ResponseT, ResultT>
implements AsyncResponseTransformer.SplitResult.Builder<ResponseT, ResultT> {
private SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher;
private CompletableFuture<ResultT> future;

DefaultBuilder() {
}

DefaultBuilder(DefaultAsyncResponseTransformerSplitResult<ResponseT, ResultT> split) {
this.publisher = split.publisher;
this.future = split.future;
}

@Override
public SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher() {
return this.publisher;
}

@Override
public AsyncResponseTransformer.SplitResult.Builder<ResponseT, ResultT> publisher(
SdkPublisher<AsyncResponseTransformer<ResponseT, ResponseT>> publisher) {
this.publisher = publisher;
return this;
}

@Override
public CompletableFuture<ResultT> resultFuture() {
return this.future;
}

@Override
public AsyncResponseTransformer.SplitResult.Builder<ResponseT, ResultT> resultFuture(CompletableFuture<ResultT> future) {
this.future = future;
return this;
}

@Override
public AsyncResponseTransformer.SplitResult<ResponseT, ResultT> build() {
return new DefaultAsyncResponseTransformerSplitResult<>(this);
}
}
}
Loading