1 /*
2 * Copyright 2015-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.handlers;
16
17 import com.amazonaws.auth.AWSCredentials;
18 import com.amazonaws.client.builder.AdvancedConfig;
19
20 /**
21 * A type safe key used for setting and retrieving context in a {@link
22 * com.amazonaws.Request} object.
23 *
24 * <pre class="brush: java">
25 * final HandlerContextKey<String> METRICS_KEY = new HandlerContextKey("METRICS_KEY");
26 *
27 * new RequestHandler2(){
28 *
29 * @Override
30 * public void beforeRequest(Request<?> request) {
31 * request.addHandlerContext(METRICS_KEY, AWSRequestMetrics
32 * .Field.HttpRequestTime.name());
33 * }
34 *
35 * @Override
36 * public void afterResponse(Request<?> request, Response<?> response) {
37 * String metricsKey = request.getHandlerContext(METRICS_KEY);
38 * }
39 *
40 * @Override
41 * public void afterError(Request<?> request, Response<?> response,
42 * Exception e) { }
43 * }
44 * </pre>
45 */
46 public class HandlerContextKey<T> {
47
48 /**
49 * The key under which the request credentials are set.
50 **/
51 public static final HandlerContextKey<AWSCredentials> AWS_CREDENTIALS = new HandlerContextKey<AWSCredentials>("AWSCredentials");
52
53 /**
54 * The region used to sign the request.
55 */
56 public static final HandlerContextKey<String> SIGNING_REGION = new HandlerContextKey<String>("SigningRegion");
57
58 /**
59 * The name of the operation for the request.
60 */
61 public static final HandlerContextKey<String> OPERATION_NAME = new HandlerContextKey<String>("OperationName");
62
63 /**
64 * The unique identifier for a service to which the request is being sent.
65 */
66 public static final HandlerContextKey<String> SERVICE_ID = new HandlerContextKey<String>("ServiceId");
67
68 /**
69 * A boolean value indicating if Content-Length header is required by the operation
70 */
71 public static final HandlerContextKey<Boolean> REQUIRES_LENGTH = new HandlerContextKey<Boolean>("RequiresLength");
72
73 /**
74 * A boolean value indicating if the input of the operation has a streaming member.
75 * If an input shape in operation has streaming trait, then it is a streaming op
76 */
77 public static final HandlerContextKey<Boolean> HAS_STREAMING_INPUT = new HandlerContextKey<Boolean>("HasStreamingInput");
78
79 /**
80 * A boolean value indicating if the output of the operation has a streaming member.
81 */
82 public static final HandlerContextKey<Boolean> HAS_STREAMING_OUTPUT = new HandlerContextKey<Boolean>("HasStreamingOutput");
83
84 /**
85 * Advanced client configuration. Contents will be service specific.
86 */
87 public static final HandlerContextKey<AdvancedConfig> ADVANCED_CONFIG = new HandlerContextKey<AdvancedConfig>("AdvancedConfig");
88
89 private final String name;
90
91 public HandlerContextKey(String name) {
92 if (name == null) {
93 throw new IllegalArgumentException("Name cannot be null");
94 }
95 this.name = name;
96 }
97
98 @Override
99 public boolean equals(Object o) {
100 if (this == o) return true;
101 if (o == null || getClass() != o.getClass()) return false;
102
103 HandlerContextKey<?> key = (HandlerContextKey<?>) o;
104
105 return name.equals(key.getName());
106
107 }
108
109 public String getName() {
110 return name;
111 }
112
113 @Override
114 public int hashCode() {
115 return name.hashCode();
116 }
117 }
118