1 /*
2  * Copyright 2011-2020 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 package com.amazonaws;
16
17 import com.amazonaws.annotation.SdkProtectedApi;
18
19 /**
20  * Factory producing predefined {@link ClientConfiguration} instances.
21  * Individual service clients may extend this factory to override
22  * these with service specific configuration values.
23  */

24 @SdkProtectedApi
25 public class ClientConfigurationFactory {
26
27     /**
28      * Builds a {@link ClientConfiguration} instance with the default configuration
29      * for the current client.  If the {@link SDKGlobalConfiguration#ENABLE_IN_REGION_OPTIMIZED_MODE}
30      * system property has been set, in-region optimized configuration will be used.
31      *
32      * @return constructed {@link ClientConfiguration} instance
33      */

34     public final ClientConfiguration getConfig() {
35         return SDKGlobalConfiguration.isInRegionOptimizedModeEnabled()
36                 ? getInRegionOptimizedConfig() : getDefaultConfig();
37     }
38
39     /**
40      * Builds a {@link ClientConfiguration} instance with default configuration
41      * values suitable for most use cases.
42      *
43      * @return constructed {@link ClientConfiguration} with standard configuration.
44      */

45     protected ClientConfiguration getDefaultConfig() {
46         return new ClientConfiguration();
47     }
48
49     /**
50      * Builds a {@link ClientConfiguration} instance with configuration values
51      * tailored towards clients operating in the same AWS region as the service
52      * endpoint they call.  Timeouts in in-region optimized configurations are
53      * generally set much lower than the client standard configuration.
54      *
55      * @return constructed {@link ClientConfiguration} with in-region optimized configuration
56      */

57     protected ClientConfiguration getInRegionOptimizedConfig() {
58         return new ClientConfiguration().withConnectionTimeout(1000);
59     }
60
61 }
62