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.core.interceptor;
17
18 import software.amazon.awssdk.annotations.SdkPublicApi;
19
20 /**
21  * An attribute attached to a particular execution, stored in {@link ExecutionAttributes}.
22  *
23  * This is typically used as a static final field in an {@link ExecutionInterceptor}:
24  * <pre>
25  * {@code
26  *  class MyExecutionInterceptor implements ExecutionInterceptor {
27  *      private static final ExecutionAttribute<String> DATA = new ExecutionAttribute<>();
28  *
29  *      public void beforeExecution(Context.BeforeExecution execution, ExecutionAttributes executionAttributes) {
30  *          executionAttributes.put(DATA, "Request: " + execution.request());
31  *      }
32  *
33  *      public void afterExecution(Context.AfterExecution execution, ExecutionAttributes executionAttributes) {
34  *          String data = executionAttributes.get(DATA); // Retrieve the value saved in beforeExecution.
35  *      }
36  *  }
37  * }
38  </pre>
39  *
40  * @param <T> The type of data associated with this attribute.
41  */

42 @SdkPublicApi
43 public final class ExecutionAttribute<T> {
44
45     private final String name;
46
47     /**
48      * Creates a new {@link ExecutionAttribute} bound to the provided type param.
49      *
50      * @param name Descriptive name for the attribute, used primarily for debugging purposes.
51      */

52     public ExecutionAttribute(String name) {
53         this.name = name;
54     }
55
56     @Override
57     public String toString() {
58         return name;
59     }
60 }
61