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
16 package com.amazonaws.metrics;
17
18 import com.amazonaws.Request;
19 import com.amazonaws.Response;
20
21 /**
22  * A service provider interface that can be used to implement an AWS SDK
23  * request/response metric collector.
24  * 
25  * @see AwsSdkMetrics
26  */

27 public abstract class RequestMetricCollector {
28     /**
29      * Can be used to serve as a factory for the request metric collector.
30      */

31     public static interface Factory {
32         /**
33          * Returns an instance of the collector; or null if if failed to create
34          * one.
35          */

36         public RequestMetricCollector getRequestMetricCollector();
37     }
38     /** 
39      * Used to collect the metric at the end of a request/response cycle.
40      *
41      * @see Request#getAWSRequestMetrics()
42      */

43     public abstract void collectMetrics(Request<?> request, Response<?> response);
44     public boolean isEnabled() { return true; }
45
46     /** A convenient instance of a no-op request metric collector. */
47     public static final RequestMetricCollector NONE = new RequestMetricCollector() {
48         @Override public void collectMetrics(Request<?> request, Response<?> response) {}
49         @Override public boolean isEnabled() { return false; }
50     };
51 }
52