Skip to content

Commit 363b59e

Browse files
authored
Hooking up max connections (#304)
* Hooking up max connections to S3 client. * Updating aws-c-s3 submodule.
1 parent e7facf2 commit 363b59e

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

s3-native-client/src/main/java/com/amazonaws/s3/S3NativeClient.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,26 @@ public class S3NativeClient implements AutoCloseable {
2323
private final S3Client s3Client;
2424
private final String signingRegion;
2525

26-
public S3NativeClient(final String signingRegion, final S3Client s3Client) {
27-
this.signingRegion = signingRegion;
28-
this.s3Client = s3Client;
29-
}
30-
3126
public S3NativeClient(final String signingRegion, final ClientBootstrap clientBootstrap,
3227
final CredentialsProvider credentialsProvider, final long partSizeBytes,
3328
final double targetThroughputGbps) {
29+
30+
this(signingRegion, clientBootstrap, credentialsProvider, partSizeBytes, targetThroughputGbps, 0);
31+
}
32+
33+
public S3NativeClient(final String signingRegion, final ClientBootstrap clientBootstrap,
34+
final CredentialsProvider credentialsProvider, final long partSizeBytes, final double targetThroughputGbps,
35+
final int maxConnections) {
36+
37+
this(signingRegion, new S3Client(new S3ClientOptions().withClientBootstrap(clientBootstrap)
38+
.withCredentialsProvider(credentialsProvider).withRegion(signingRegion).withPartSize(partSizeBytes)
39+
.withThroughputTargetGbps(targetThroughputGbps).withMaxConnections(maxConnections)));
40+
}
41+
42+
public S3NativeClient(final String signingRegion, final S3Client s3Client) {
3443
// keep signing region to construct Host header per-request
3544
this.signingRegion = signingRegion;
36-
final S3ClientOptions clientOptions = new S3ClientOptions().withClientBootstrap(clientBootstrap)
37-
.withCredentialsProvider(credentialsProvider).withRegion(signingRegion).withPartSize(partSizeBytes)
38-
.withThroughputTargetGbps(targetThroughputGbps);
39-
s3Client = new S3Client(clientOptions);
45+
this.s3Client = s3Client;
4046
}
4147

4248
private void addCustomHeaders(List<HttpHeader> headers, HttpHeader[] customHeaders) {

src/main/java/software/amazon/awssdk/crt/s3/S3Client.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public class S3Client extends CrtResource {
2222
public S3Client(S3ClientOptions options) throws CrtRuntimeException {
2323
TlsContext tlsCtx = options.getTlsContext();
2424

25-
acquireNativeHandle(s3ClientNew(this, options.getRegion().getBytes(UTF8),
25+
acquireNativeHandle(s3ClientNew(this, options.getRegion().getBytes(UTF8),
2626
options.getEndpoint() != null ? options.getEndpoint().getBytes(UTF8) : null,
2727
options.getClientBootstrap().getNativeHandle(), tlsCtx != null ? tlsCtx.getNativeHandle() : 0,
28-
options.getCredentialsProvider().getNativeHandle(),
29-
options.getPartSize(), options.getThroughputTargetGbps()));
28+
options.getCredentialsProvider().getNativeHandle(), options.getPartSize(),
29+
options.getThroughputTargetGbps(), options.getMaxConnections()));
3030

3131
addReferenceTo(options.getClientBootstrap());
3232
addReferenceTo(options.getCredentialsProvider());
@@ -40,13 +40,15 @@ private void onShutdownComplete() {
4040

4141
public S3MetaRequest makeMetaRequest(S3MetaRequestOptions options) {
4242

43-
if(options.getHttpRequest() == null) {
44-
Log.log(Log.LogLevel.Error, Log.LogSubject.S3Client, "S3Client.makeMetaRequest has invalid options; Http Request cannot be null.");
43+
if (options.getHttpRequest() == null) {
44+
Log.log(Log.LogLevel.Error, Log.LogSubject.S3Client,
45+
"S3Client.makeMetaRequest has invalid options; Http Request cannot be null.");
4546
return null;
4647
}
4748

48-
if(options.getResponseHandler() == null) {
49-
Log.log(Log.LogLevel.Error, Log.LogSubject.S3Client, "S3Client.makeMetaRequest has invalid options; Response Handler cannot be null.");
49+
if (options.getResponseHandler() == null) {
50+
Log.log(Log.LogLevel.Error, Log.LogSubject.S3Client,
51+
"S3Client.makeMetaRequest has invalid options; Response Handler cannot be null.");
5052
return null;
5153
}
5254

@@ -56,7 +58,6 @@ public S3MetaRequest makeMetaRequest(S3MetaRequestOptions options) {
5658

5759
byte[] httpRequestBytes = options.getHttpRequest().marshalForJni();
5860

59-
6061
long metaRequestNativeHandle = s3ClientMakeMetaRequest(getNativeHandle(), metaRequest,
6162
options.getMetaRequestType().getNativeValue(), httpRequestBytes,
6263
options.getHttpRequest().getBodyStream(), responseHandlerNativeAdapter);
@@ -95,11 +96,12 @@ public CompletableFuture<Void> getShutdownCompleteFuture() {
9596
* native methods
9697
******************************************************************************/
9798
private static native long s3ClientNew(S3Client thisObj, byte[] region, byte[] endpoint, long clientBootstrap,
98-
long tlsContext,
99-
long signingConfig, long partSize, double throughputTargetGbps) throws CrtRuntimeException;
99+
long tlsContext, long signingConfig, long partSize, double throughputTargetGbps, int maxConnections)
100+
throws CrtRuntimeException;
100101

101102
private static native void s3ClientDestroy(long client);
102103

103104
private static native long s3ClientMakeMetaRequest(long clientId, S3MetaRequest metaRequest, int metaRequestType,
104-
byte[] httpRequestBytes, HttpRequestBodyStream httpRequestBodyStream, S3MetaRequestResponseHandlerNativeAdapter responseHandlerNativeAdapter);
105+
byte[] httpRequestBytes, HttpRequestBodyStream httpRequestBodyStream,
106+
S3MetaRequestResponseHandlerNativeAdapter responseHandlerNativeAdapter);
105107
}

src/main/java/software/amazon/awssdk/crt/s3/S3ClientOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class S3ClientOptions {
1313
private CredentialsProvider credentialsProvider;
1414
private long partSize;
1515
private double throughputTargetGbps;
16+
private int maxConnections;
1617

1718
public S3ClientOptions() {
1819

@@ -80,4 +81,13 @@ public S3ClientOptions withTlsContext(TlsContext tlsContext) {
8081
public TlsContext getTlsContext() {
8182
return tlsContext;
8283
}
84+
85+
public S3ClientOptions withMaxConnections(int maxConnections) {
86+
this.maxConnections = maxConnections;
87+
return this;
88+
}
89+
90+
public int getMaxConnections() {
91+
return maxConnections;
92+
}
8393
}

src/native/s3_client.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_s3_S3Client_s3ClientNew(
4747
jlong jni_tls_ctx,
4848
jlong jni_credentials_provider,
4949
jlong part_size,
50-
jdouble throughput_target_gbps) {
50+
jdouble throughput_target_gbps,
51+
int max_connections) {
5152
(void)jni_class;
5253

5354
struct aws_allocator *allocator = aws_jni_get_allocator();
@@ -92,6 +93,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_s3_S3Client_s3ClientNew(
9293
}
9394

9495
struct aws_s3_client_config client_config = {
96+
.max_active_connections_override = max_connections,
9597
.region = region,
9698
.client_bootstrap = client_bootstrap,
9799
.tls_connection_options = tls_options,

0 commit comments

Comments
 (0)