• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.http.crt.internal;
17 
18 import java.time.Duration;
19 import java.util.function.Consumer;
20 import software.amazon.awssdk.annotations.SdkInternalApi;
21 import software.amazon.awssdk.http.SdkHttpConfigurationOption;
22 import software.amazon.awssdk.http.crt.ConnectionHealthConfiguration;
23 import software.amazon.awssdk.http.crt.ProxyConfiguration;
24 import software.amazon.awssdk.http.crt.TcpKeepAliveConfiguration;
25 import software.amazon.awssdk.utils.AttributeMap;
26 import software.amazon.awssdk.utils.Validate;
27 
28 @SdkInternalApi
29 public class AwsCrtClientBuilderBase<BuilderT> {
30     private final AttributeMap.Builder standardOptions = AttributeMap.builder();
31     private Long readBufferSize;
32     private ProxyConfiguration proxyConfiguration;
33     private ConnectionHealthConfiguration connectionHealthConfiguration;
34     private TcpKeepAliveConfiguration tcpKeepAliveConfiguration;
35     private Boolean postQuantumTlsEnabled;
36 
AwsCrtClientBuilderBase()37     protected AwsCrtClientBuilderBase() {
38     }
39 
getAttributeMap()40     protected AttributeMap.Builder getAttributeMap() {
41         return standardOptions;
42     }
43 
thisBuilder()44     private BuilderT thisBuilder() {
45         return (BuilderT) this;
46     }
47 
maxConcurrency(Integer maxConcurrency)48     public BuilderT maxConcurrency(Integer maxConcurrency) {
49         Validate.isPositiveOrNull(maxConcurrency, "maxConcurrency");
50         standardOptions.put(SdkHttpConfigurationOption.MAX_CONNECTIONS, maxConcurrency);
51         return thisBuilder();
52     }
53 
readBufferSizeInBytes(Long readBufferSize)54     public BuilderT readBufferSizeInBytes(Long readBufferSize) {
55         Validate.isPositiveOrNull(readBufferSize, "readBufferSize");
56         this.readBufferSize = readBufferSize;
57         return thisBuilder();
58     }
59 
getReadBufferSizeInBytes()60     public Long getReadBufferSizeInBytes() {
61         return this.readBufferSize;
62     }
63 
64 
proxyConfiguration(ProxyConfiguration proxyConfiguration)65     public BuilderT proxyConfiguration(ProxyConfiguration proxyConfiguration) {
66         this.proxyConfiguration = proxyConfiguration;
67         return thisBuilder();
68     }
69 
getProxyConfiguration()70     public ProxyConfiguration getProxyConfiguration() {
71         return this.proxyConfiguration;
72     }
73 
connectionHealthConfiguration(ConnectionHealthConfiguration monitoringOptions)74     public BuilderT connectionHealthConfiguration(ConnectionHealthConfiguration monitoringOptions) {
75         this.connectionHealthConfiguration = monitoringOptions;
76         return thisBuilder();
77     }
78 
getConnectionHealthConfiguration()79     public ConnectionHealthConfiguration getConnectionHealthConfiguration() {
80         return this.connectionHealthConfiguration;
81     }
82 
connectionHealthConfiguration(Consumer<ConnectionHealthConfiguration.Builder> configurationBuilder)83     public BuilderT connectionHealthConfiguration(Consumer<ConnectionHealthConfiguration.Builder>
84                                            configurationBuilder) {
85         ConnectionHealthConfiguration.Builder builder = ConnectionHealthConfiguration.builder();
86         configurationBuilder.accept(builder);
87         connectionHealthConfiguration(builder.build());
88         return thisBuilder();
89     }
90 
connectionMaxIdleTime(Duration connectionMaxIdleTime)91     public BuilderT connectionMaxIdleTime(Duration connectionMaxIdleTime) {
92         Validate.isPositive(connectionMaxIdleTime, "connectionMaxIdleTime");
93         standardOptions.put(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT, connectionMaxIdleTime);
94         return thisBuilder();
95     }
96 
connectionTimeout(Duration connectionTimeout)97     public BuilderT connectionTimeout(Duration connectionTimeout) {
98         Validate.isPositive(connectionTimeout, "connectionTimeout");
99         standardOptions.put(SdkHttpConfigurationOption.CONNECTION_TIMEOUT, connectionTimeout);
100         return thisBuilder();
101     }
102 
tcpKeepAliveConfiguration(TcpKeepAliveConfiguration tcpKeepAliveConfiguration)103     public BuilderT tcpKeepAliveConfiguration(TcpKeepAliveConfiguration tcpKeepAliveConfiguration) {
104         this.tcpKeepAliveConfiguration = tcpKeepAliveConfiguration;
105         return thisBuilder();
106     }
107 
getTcpKeepAliveConfiguration()108     public TcpKeepAliveConfiguration getTcpKeepAliveConfiguration() {
109         return this.tcpKeepAliveConfiguration;
110     }
111 
tcpKeepAliveConfiguration(Consumer<TcpKeepAliveConfiguration.Builder> tcpKeepAliveConfigurationBuilder)112     public BuilderT tcpKeepAliveConfiguration(Consumer<TcpKeepAliveConfiguration.Builder>
113                                        tcpKeepAliveConfigurationBuilder) {
114         TcpKeepAliveConfiguration.Builder builder = TcpKeepAliveConfiguration.builder();
115         tcpKeepAliveConfigurationBuilder.accept(builder);
116         tcpKeepAliveConfiguration(builder.build());
117         return thisBuilder();
118     }
119 
postQuantumTlsEnabled(Boolean postQuantumTlsEnabled)120     public BuilderT postQuantumTlsEnabled(Boolean postQuantumTlsEnabled) {
121         this.postQuantumTlsEnabled = postQuantumTlsEnabled;
122         return thisBuilder();
123     }
124 
getPostQuantumTlsEnabled()125     public Boolean getPostQuantumTlsEnabled() {
126         return this.postQuantumTlsEnabled;
127     }
128 
proxyConfiguration(Consumer<ProxyConfiguration.Builder> proxyConfigurationBuilderConsumer)129     public BuilderT proxyConfiguration(Consumer<ProxyConfiguration.Builder> proxyConfigurationBuilderConsumer) {
130         ProxyConfiguration.Builder builder = ProxyConfiguration.builder();
131         proxyConfigurationBuilderConsumer.accept(builder);
132         proxyConfiguration(builder.build());
133         return thisBuilder();
134     }
135 }