Skip to content

Commit cf9c41a

Browse files
committed
Adding SdkClient interface that all service clients extend from.
1 parent 0c958ab commit cf9c41a

File tree

13 files changed

+89
-7
lines changed

13 files changed

+89
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"type": "feature",
4+
"description": "Added `SdkClient` base interface that all service clients implement."
5+
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClass.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public TypeSpec poetSpec() {
5858
.addSuperinterface(interfaceClass)
5959
.addJavadoc("Internal implementation of {@link $1T}.\n\n@see $1T#builder()",
6060
interfaceClass)
61+
.addMethod(nameMethod())
6162
.addMethods(operations())
6263
.addMethod(closeMethod())
6364
.addMethods(protocolSpec.additionalMethods())
@@ -84,6 +85,15 @@ private MethodSpec constructor() {
8485
.build();
8586
}
8687

88+
private MethodSpec nameMethod() {
89+
return MethodSpec.methodBuilder("serviceName")
90+
.addAnnotation(Override.class)
91+
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
92+
.returns(String.class)
93+
.addStatement("return SERVICE_NAME")
94+
.build();
95+
}
96+
8797
private MethodSpec constructorWithAdvancedConfiguration() {
8898
ClassName advancedConfiguration = ClassName.get(basePackage,
8999
model.getCustomizationConfig().getServiceSpecificClientConfigClass());

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/AsyncClientInterface.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static java.util.stream.Collectors.toList;
1919

2020
import com.squareup.javapoet.ClassName;
21+
import com.squareup.javapoet.FieldSpec;
2122
import com.squareup.javapoet.MethodSpec;
2223
import com.squareup.javapoet.ParameterizedTypeName;
2324
import com.squareup.javapoet.TypeName;
@@ -36,6 +37,7 @@
3637
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
3738
import software.amazon.awssdk.codegen.poet.ClassSpec;
3839
import software.amazon.awssdk.codegen.poet.PoetUtils;
40+
import software.amazon.awssdk.core.SdkClient;
3941
import software.amazon.awssdk.core.async.AsyncRequestProvider;
4042
import software.amazon.awssdk.core.async.AsyncResponseHandler;
4143
import software.amazon.awssdk.core.auth.DefaultCredentialsProvider;
@@ -62,8 +64,13 @@ public AsyncClientInterface(IntermediateModel model) {
6264
@Override
6365
public TypeSpec poetSpec() {
6466
return PoetUtils.createInterfaceBuilder(className)
67+
.addSuperinterface(SdkClient.class)
6568
.addSuperinterface(SdkAutoCloseable.class)
6669
.addJavadoc(getJavadoc())
70+
.addField(FieldSpec.builder(String.class, "SERVICE_NAME")
71+
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
72+
.initializer("$S", model.getMetadata().getSigningName())
73+
.build())
6774
.addMethod(create())
6875
.addMethod(builder())
6976
.addMethods(operationsAndSimpleMethods())

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientClass.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public TypeSpec poetSpec() {
7474
.addField(ClientHandler.class, "clientHandler", PRIVATE, FINAL)
7575
.addField(protocolSpec.protocolFactory(model))
7676
.addField(ClientConfiguration.class, "clientConfiguration", PRIVATE, FINAL)
77+
.addMethod(nameMethod())
7778
.addMethods(operations());
7879

7980
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
@@ -93,6 +94,15 @@ public TypeSpec poetSpec() {
9394
return classBuilder.build();
9495
}
9596

97+
private MethodSpec nameMethod() {
98+
return MethodSpec.methodBuilder("serviceName")
99+
.addAnnotation(Override.class)
100+
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
101+
.returns(String.class)
102+
.addStatement("return SERVICE_NAME")
103+
.build();
104+
}
105+
96106
@Override
97107
public ClassName className() {
98108
return className;

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/SyncClientInterface.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import software.amazon.awssdk.codegen.poet.PoetExtensions;
4040
import software.amazon.awssdk.codegen.poet.PoetUtils;
4141
import software.amazon.awssdk.codegen.utils.PaginatorUtils;
42+
import software.amazon.awssdk.core.SdkClient;
4243
import software.amazon.awssdk.core.auth.DefaultCredentialsProvider;
4344
import software.amazon.awssdk.core.exception.SdkClientException;
4445
import software.amazon.awssdk.core.exception.SdkServiceException;
@@ -67,6 +68,7 @@ public SyncClientInterface(IntermediateModel model) {
6768
@Override
6869
public TypeSpec poetSpec() {
6970
return PoetUtils.createInterfaceBuilder(className)
71+
.addSuperinterface(SdkClient.class)
7072
.addSuperinterface(SdkAutoCloseable.class)
7173
.addJavadoc(getJavadoc())
7274
.addField(FieldSpec.builder(String.class, "SERVICE_NAME")

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-async-client-class.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ protected DefaultJsonAsyncClient(AsyncClientConfiguration clientConfiguration, A
6363
this.protocolFactory = init();
6464
}
6565

66+
@Override
67+
public final String serviceName() {
68+
return SERVICE_NAME;
69+
}
70+
6671
/**
6772
* <p>
6873
* Performs a post operation to the query service and has no output

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-async-client-interface.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.concurrent.CompletableFuture;
55
import java.util.function.Consumer;
66
import javax.annotation.Generated;
7+
import software.amazon.awssdk.core.SdkClient;
78
import software.amazon.awssdk.core.async.AsyncRequestProvider;
89
import software.amazon.awssdk.core.async.AsyncResponseHandler;
910
import software.amazon.awssdk.services.json.model.APostOperationRequest;
@@ -29,7 +30,9 @@
2930
* A service that is implemented using the query protocol
3031
*/
3132
@Generated("software.amazon.awssdk:codegen")
32-
public interface JsonAsyncClient extends SdkAutoCloseable {
33+
public interface JsonAsyncClient extends SdkClient, SdkAutoCloseable {
34+
String SERVICE_NAME = "json-service";
35+
3336
/**
3437
* Create a {@link JsonAsyncClient} with the region loaded from the
3538
* {@link software.amazon.awssdk.core.regions.providers.DefaultAwsRegionProviderChain} and credentials loaded from

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-class.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ protected DefaultJsonClient(SyncClientConfiguration clientConfiguration, Advance
7171
this.clientConfiguration = clientConfiguration;
7272
}
7373

74+
@Override
75+
public final String serviceName() {
76+
return SERVICE_NAME;
77+
}
78+
7479
/**
7580
* <p>
7681
* Performs a post operation to the query service and has no output

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-json-client-interface.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.nio.file.Path;
44
import java.util.function.Consumer;
55
import javax.annotation.Generated;
6+
import software.amazon.awssdk.core.SdkClient;
67
import software.amazon.awssdk.core.exception.SdkClientException;
78
import software.amazon.awssdk.core.exception.SdkServiceException;
89
import software.amazon.awssdk.core.regions.ServiceMetadata;
@@ -36,7 +37,7 @@
3637
* A service that is implemented using the query protocol
3738
*/
3839
@Generated("software.amazon.awssdk:codegen")
39-
public interface JsonClient extends SdkAutoCloseable {
40+
public interface JsonClient extends SdkClient, SdkAutoCloseable {
4041
String SERVICE_NAME = "json-service";
4142

4243
/**

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/test-query-client-class.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ protected DefaultQueryClient(SyncClientConfiguration clientConfiguration) {
4848
this.clientConfiguration = clientConfiguration;
4949
}
5050

51+
@Override
52+
public final String serviceName() {
53+
return SERVICE_NAME;
54+
}
55+
5156
/**
5257
* <p>
5358
* Performs a post operation to the query service and has no output
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.core;
17+
18+
/**
19+
* All SDK service client interfaces should extend this interface.
20+
*/
21+
public interface SdkClient {
22+
23+
/**
24+
* The name of the service.
25+
*
26+
* @return name for this service.
27+
*/
28+
String serviceName();
29+
}

http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/ApacheHttpClientFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import software.amazon.awssdk.http.apache.internal.conn.ClientConnectionManagerFactory;
3131
import software.amazon.awssdk.http.apache.internal.conn.SdkConnectionKeepAliveStrategy;
3232
import software.amazon.awssdk.http.apache.internal.impl.ApacheConnectionManagerFactory;
33-
import software.amazon.awssdk.http.apache.internal.impl.ApacheSdkClient;
33+
import software.amazon.awssdk.http.apache.internal.impl.ApacheSdkHttpClient;
3434
import software.amazon.awssdk.http.apache.internal.impl.ConnectionManagerAwareHttpClient;
3535
import software.amazon.awssdk.http.apache.internal.utils.ApacheUtils;
3636
import software.amazon.awssdk.utils.AttributeMap;
@@ -72,7 +72,7 @@ private ConnectionManagerAwareHttpClient createClient(ApacheSdkHttpClientFactory
7272
// IdleConnectionReaper.registerConnectionManager(cm, settings.getMaxIdleConnectionTime());
7373
// }
7474

75-
return new ApacheSdkClient(builder.build(), cm);
75+
return new ApacheSdkHttpClient(builder.build(), cm);
7676
}
7777

7878
private void addProxyConfig(HttpClientBuilder builder,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
/**
3131
* An instance of {@link ConnectionManagerAwareHttpClient} that delegates all the requests to the given http client.
3232
*/
33-
public class ApacheSdkClient implements ConnectionManagerAwareHttpClient {
33+
public class ApacheSdkHttpClient implements ConnectionManagerAwareHttpClient {
3434

3535
private final HttpClient delegate;
3636

3737
private final HttpClientConnectionManager cm;
3838

39-
public ApacheSdkClient(final HttpClient delegate,
40-
final HttpClientConnectionManager cm) {
39+
public ApacheSdkHttpClient(final HttpClient delegate,
40+
final HttpClientConnectionManager cm) {
4141
if (delegate == null) {
4242
throw new IllegalArgumentException("delegate " +
4343
"cannot be null");

0 commit comments

Comments
 (0)