1 /*
2  * Copyright 2010-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.Request;
18 import com.amazonaws.Response;
19 import com.amazonaws.util.AWSRequestMetrics;
20 import com.amazonaws.util.TimingInfo;
21
22 /**
23  * Internal class used to adapt a request handler that implements the
24  * deprecated {@link RequestHandler} interface to the deprecating
25  * {@link RequestHandler2} interface.
26  */

27 final class RequestHandler2Adaptor extends RequestHandler2 {
28     @SuppressWarnings("deprecation")
29     private final RequestHandler old;
30     RequestHandler2Adaptor(@SuppressWarnings("deprecation") RequestHandler old) {
31         if (old == null)
32             throw new IllegalArgumentException();
33         this.old = old;
34     }
35     @SuppressWarnings("deprecation")
36     @Override public void beforeRequest(Request<?> request) {
37         old.beforeRequest(request);
38     }
39
40     @SuppressWarnings("deprecation")
41     @Override
42     public void afterResponse(Request<?> request, Response<?> response) {
43         AWSRequestMetrics awsRequestMetrics = request == null ? null : request
44                 .getAWSRequestMetrics();
45         Object awsResponse = response == null ? null : response
46                 .getAwsResponse();
47         TimingInfo timingInfo = awsRequestMetrics == null ? null
48                 : awsRequestMetrics.getTimingInfo();
49         old.afterResponse(request, awsResponse, timingInfo);
50     }
51
52     @SuppressWarnings("deprecation")
53     @Override public void afterError(Request<?> request, Response<?> response,
54             Exception e) {
55         old.afterError(request, e);
56     }
57
58     @Override public int hashCode() {
59         return old.hashCode();
60     }
61
62     @Override public boolean equals(Object o) {
63         if (!(o instanceof RequestHandler2Adaptor))
64             return false;
65         RequestHandler2Adaptor that = (RequestHandler2Adaptor)o;
66         return this.old.equals(that.old);
67     }
68 }
69