• 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.nio.netty.internal;
17 
18 import static software.amazon.awssdk.http.SdkHttpConfigurationOption.CONNECTION_ACQUIRE_TIMEOUT;
19 import static software.amazon.awssdk.http.SdkHttpConfigurationOption.CONNECTION_TIMEOUT;
20 import static software.amazon.awssdk.http.SdkHttpConfigurationOption.MAX_CONNECTIONS;
21 import static software.amazon.awssdk.http.SdkHttpConfigurationOption.MAX_PENDING_CONNECTION_ACQUIRES;
22 import static software.amazon.awssdk.http.SdkHttpConfigurationOption.TCP_KEEPALIVE;
23 import static software.amazon.awssdk.http.SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES;
24 import static software.amazon.awssdk.utils.NumericUtils.saturatedCast;
25 
26 import java.time.Duration;
27 import software.amazon.awssdk.annotations.SdkInternalApi;
28 import software.amazon.awssdk.http.SdkHttpConfigurationOption;
29 import software.amazon.awssdk.http.TlsKeyManagersProvider;
30 import software.amazon.awssdk.http.TlsTrustManagersProvider;
31 import software.amazon.awssdk.utils.AttributeMap;
32 
33 /**
34  * Internal object for configuring netty.
35  */
36 @SdkInternalApi
37 public final class NettyConfiguration {
38 
39     public static final int CHANNEL_POOL_CLOSE_TIMEOUT_SECONDS = 5;
40     public static final int EVENTLOOP_SHUTDOWN_QUIET_PERIOD_SECONDS = 2;
41     public static final int EVENTLOOP_SHUTDOWN_TIMEOUT_SECONDS = 15;
42     public static final int EVENTLOOP_SHUTDOWN_FUTURE_TIMEOUT_SECONDS = 16;
43     public static final int HTTP2_CONNECTION_PING_TIMEOUT_SECONDS = 5;
44 
45     private final AttributeMap configuration;
46 
NettyConfiguration(AttributeMap configuration)47     public NettyConfiguration(AttributeMap configuration) {
48         this.configuration = configuration;
49     }
50 
attribute(AttributeMap.Key<T> key)51     public <T> T attribute(AttributeMap.Key<T> key) {
52         return configuration.get(key);
53     }
54 
connectTimeoutMillis()55     public int connectTimeoutMillis() {
56         return saturatedCast(configuration.get(CONNECTION_TIMEOUT).toMillis());
57     }
58 
connectionAcquireTimeoutMillis()59     public int connectionAcquireTimeoutMillis() {
60         return saturatedCast(configuration.get(CONNECTION_ACQUIRE_TIMEOUT).toMillis());
61     }
62 
maxConnections()63     public int maxConnections() {
64         return configuration.get(MAX_CONNECTIONS);
65     }
66 
maxPendingConnectionAcquires()67     public int maxPendingConnectionAcquires() {
68         return configuration.get(MAX_PENDING_CONNECTION_ACQUIRES);
69     }
70 
readTimeoutMillis()71     public int readTimeoutMillis() {
72         return saturatedCast(configuration.get(SdkHttpConfigurationOption.READ_TIMEOUT).toMillis());
73     }
74 
writeTimeoutMillis()75     public int writeTimeoutMillis() {
76         return saturatedCast(configuration.get(SdkHttpConfigurationOption.WRITE_TIMEOUT).toMillis());
77     }
78 
idleTimeoutMillis()79     public int idleTimeoutMillis() {
80         return saturatedCast(configuration.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis());
81     }
82 
connectionTtlMillis()83     public int connectionTtlMillis() {
84         return saturatedCast(configuration.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE).toMillis());
85     }
86 
reapIdleConnections()87     public boolean reapIdleConnections() {
88         return configuration.get(SdkHttpConfigurationOption.REAP_IDLE_CONNECTIONS);
89     }
90 
tlsKeyManagersProvider()91     public TlsKeyManagersProvider tlsKeyManagersProvider() {
92         return configuration.get(SdkHttpConfigurationOption.TLS_KEY_MANAGERS_PROVIDER);
93     }
94 
tlsTrustManagersProvider()95     public TlsTrustManagersProvider tlsTrustManagersProvider() {
96         return configuration.get(SdkHttpConfigurationOption.TLS_TRUST_MANAGERS_PROVIDER);
97     }
98 
trustAllCertificates()99     public boolean trustAllCertificates() {
100         return configuration.get(TRUST_ALL_CERTIFICATES);
101     }
102 
tcpKeepAlive()103     public boolean tcpKeepAlive() {
104         return configuration.get(TCP_KEEPALIVE);
105     }
106 
tlsHandshakeTimeout()107     public Duration tlsHandshakeTimeout() {
108         return configuration.get(SdkHttpConfigurationOption.TLS_NEGOTIATION_TIMEOUT);
109     }
110 }
111