|
| 1 | +/* |
| 2 | + * Copyright 2017-2024 original authors |
| 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 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.micronaut.aws.sdk.v2.service.lambda; |
| 17 | + |
| 18 | +import io.micronaut.aws.sdk.v2.service.AWSServiceConfiguration; |
| 19 | +import io.micronaut.aws.sdk.v2.service.AwsClientFactory; |
| 20 | +import io.micronaut.aws.ua.UserAgentProvider; |
| 21 | +import io.micronaut.context.annotation.Bean; |
| 22 | +import io.micronaut.context.annotation.Factory; |
| 23 | +import io.micronaut.context.annotation.Requires; |
| 24 | +import io.micronaut.core.annotation.Nullable; |
| 25 | +import jakarta.inject.Named; |
| 26 | +import jakarta.inject.Singleton; |
| 27 | +import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain; |
| 28 | +import software.amazon.awssdk.http.SdkHttpClient; |
| 29 | +import software.amazon.awssdk.http.async.SdkAsyncHttpClient; |
| 30 | +import software.amazon.awssdk.regions.providers.AwsRegionProviderChain; |
| 31 | +import software.amazon.awssdk.services.lambda.LambdaAsyncClient; |
| 32 | +import software.amazon.awssdk.services.lambda.LambdaAsyncClientBuilder; |
| 33 | +import software.amazon.awssdk.services.lambda.LambdaClient; |
| 34 | +import software.amazon.awssdk.services.lambda.LambdaClientBuilder; |
| 35 | + |
| 36 | +/** |
| 37 | + * Factory that creates {@link LambdaClient} and {@link LambdaAsyncClient}. |
| 38 | + * @since 4.7.0 |
| 39 | + */ |
| 40 | +@Factory |
| 41 | +class LambdaClientFactory extends AwsClientFactory<LambdaClientBuilder, LambdaAsyncClientBuilder, LambdaClient, LambdaAsyncClient> { |
| 42 | + /** |
| 43 | + * Constructor. |
| 44 | + * |
| 45 | + * @param credentialsProvider The credentials provider |
| 46 | + * @param regionProvider The region provider |
| 47 | + * @param userAgentProvider User-Agent Provider |
| 48 | + * @param awsServiceConfiguration AWS Service Configuration |
| 49 | + */ |
| 50 | + protected LambdaClientFactory(AwsCredentialsProviderChain credentialsProvider, |
| 51 | + AwsRegionProviderChain regionProvider, |
| 52 | + @Nullable UserAgentProvider userAgentProvider, |
| 53 | + @Nullable @Named(LambdaClient.SERVICE_NAME) AWSServiceConfiguration awsServiceConfiguration) { |
| 54 | + super(credentialsProvider, regionProvider, userAgentProvider, awsServiceConfiguration); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + protected LambdaClientBuilder createSyncBuilder() { |
| 59 | + return LambdaClient.builder(); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + protected LambdaAsyncClientBuilder createAsyncBuilder() { |
| 64 | + return LambdaAsyncClient.builder(); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + @Singleton |
| 69 | + public LambdaClientBuilder syncBuilder(SdkHttpClient httpClient) { |
| 70 | + return super.syncBuilder(httpClient); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + @Bean(preDestroy = "close") |
| 75 | + @Singleton |
| 76 | + public LambdaClient syncClient(LambdaClientBuilder builder) { |
| 77 | + return super.syncClient(builder); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + @Singleton |
| 82 | + @Requires(beans = SdkAsyncHttpClient.class) |
| 83 | + public LambdaAsyncClientBuilder asyncBuilder(SdkAsyncHttpClient httpClient) { |
| 84 | + return super.asyncBuilder(httpClient); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + @Bean(preDestroy = "close") |
| 89 | + @Singleton |
| 90 | + @Requires(beans = SdkAsyncHttpClient.class) |
| 91 | + public LambdaAsyncClient asyncClient(LambdaAsyncClientBuilder builder) { |
| 92 | + return super.asyncClient(builder); |
| 93 | + } |
| 94 | +} |
0 commit comments