|
| 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.services.s3.internal.crossregion; |
| 17 | + |
| 18 | +import java.util.Optional; |
| 19 | +import java.util.function.Function; |
| 20 | +import software.amazon.awssdk.annotations.SdkInternalApi; |
| 21 | +import software.amazon.awssdk.services.s3.DelegatingS3Client; |
| 22 | +import software.amazon.awssdk.services.s3.S3Client; |
| 23 | +import software.amazon.awssdk.services.s3.model.S3Request; |
| 24 | + |
| 25 | +@SdkInternalApi |
| 26 | +public final class S3CrossRegionSyncClient extends DelegatingS3Client { |
| 27 | + |
| 28 | + public S3CrossRegionSyncClient(S3Client s3Client) { |
| 29 | + super(s3Client); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + protected <T extends S3Request, ReturnT> ReturnT invokeOperation(T request, Function<T, ReturnT> operation) { |
| 34 | + Optional<String> bucket = request.getValueForField("bucket", String.class); |
| 35 | + |
| 36 | + if (bucket.isPresent()) { |
| 37 | + try { |
| 38 | + operation.apply(request); //TODO: add modifyRequest logic |
| 39 | + } catch (Exception e) { |
| 40 | + handleOperationFailure(e, bucket.get()); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return operation.apply(request); |
| 45 | + } |
| 46 | + |
| 47 | + private void handleOperationFailure(Throwable t, String bucket) { |
| 48 | + //TODO: handle failure case |
| 49 | + } |
| 50 | +} |
0 commit comments