-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to configure connection timeout, keep-alive settings,…
… and advanced SocketOptions on the AwsCrtAsyncHttpClient. This is necessary for any clients with long-running connections that exceed default socket timeouts of services along the call path, and need to enable keep-alive settings which the CRT client supports, but the Java client wasn't exposing to callers
- Loading branch information
Showing
7 changed files
with
535 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "feature", | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "nikp", | ||
"description": "Add the ability to configure connection timeout, keep-alive settings, and other advanced SocketOptions on the AwsCrtAsyncHttpClient to support long-running connections" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...-crt-client/src/main/java/software/amazon/awssdk/http/crt/SocketOptionsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* 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.http.crt; | ||
|
||
import software.amazon.awssdk.annotations.SdkPreviewApi; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.crt.io.SocketOptions; | ||
import software.amazon.awssdk.utils.Validate; | ||
|
||
/** | ||
* Configuration that defines socket options for all connections established by | ||
* the {@link SocketOptionsConfiguration}. | ||
* | ||
* <b>NOTE:</b> This is a Preview API and is subject to change so it should not be used in production. | ||
*/ | ||
@SdkPublicApi | ||
@SdkPreviewApi | ||
public final class SocketOptionsConfiguration { | ||
|
||
private final SocketOptions.SocketDomain domain; | ||
private final SocketOptions.SocketType type; | ||
|
||
private SocketOptionsConfiguration(DefaultSocketOptionsConfigurationBuilder builder) { | ||
this.domain = Validate.paramNotNull(builder.domain, | ||
"domain"); | ||
this.type = Validate.paramNotNull(builder.type, | ||
"type"); | ||
} | ||
|
||
/** | ||
* @return socket domain | ||
*/ | ||
public SocketOptions.SocketDomain domain() { | ||
return domain; | ||
} | ||
|
||
/** | ||
* @return socket type | ||
*/ | ||
public SocketOptions.SocketType type() { | ||
return type; | ||
} | ||
|
||
public static Builder builder() { | ||
return new DefaultSocketOptionsConfigurationBuilder(); | ||
} | ||
|
||
/** | ||
* A builder for {@link SocketOptionsConfiguration}. | ||
* | ||
* <p>All implementations of this interface are mutable and not thread safe.</p> | ||
*/ | ||
public interface Builder { | ||
|
||
/** | ||
* Sets the socket domain | ||
* @param domain socket domain | ||
* @return Builder | ||
*/ | ||
Builder domain(SocketOptions.SocketDomain domain); | ||
|
||
/** | ||
* Sets the socket type | ||
* @param type socket type | ||
* @return Builder | ||
*/ | ||
Builder type(SocketOptions.SocketType type); | ||
|
||
SocketOptionsConfiguration build(); | ||
} | ||
|
||
/** | ||
* An SDK-internal implementation of {@link Builder}. | ||
*/ | ||
private static final class DefaultSocketOptionsConfigurationBuilder implements Builder { | ||
|
||
private SocketOptions.SocketDomain domain = SocketOptions.SocketDomain.IPv6; | ||
private SocketOptions.SocketType type = SocketOptions.SocketType.STREAM; | ||
|
||
private DefaultSocketOptionsConfigurationBuilder() { | ||
} | ||
|
||
/** | ||
* Sets the socket domain | ||
* Default: {@link SocketOptions.SocketDomain#IPv6} | ||
* @param domain socket domain | ||
* @return Builder | ||
*/ | ||
@Override | ||
public Builder domain(SocketOptions.SocketDomain domain) { | ||
this.domain = domain; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the socket type | ||
* Default: {@link SocketOptions.SocketType#STREAM} | ||
* @param type socket type | ||
* @return Builder | ||
*/ | ||
@Override | ||
public Builder type(SocketOptions.SocketType type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
@Override | ||
public SocketOptionsConfiguration build() { | ||
return new SocketOptionsConfiguration(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.