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 /** 17 * Used to collect metrics collected by the SDK. 18 * <p> 19 * Collectors are allowed to nest, allowing metrics to be collected within the 20 * context of other metrics. 21 */ 22 @NotThreadSafe 23 @SdkPublicApi 24 public interface MetricCollector { 25 /** 26 * @return The name of this collector. 27 */ name()28 String name(); 29 30 /** 31 * Report a metric. 32 */ reportMetric(SdkMetric<T> metric, T value)33 <T> void reportMetric(SdkMetric<T> metric, T value); 34 35 /** 36 * 37 * @param name The name of the child collector. 38 * @return The child collector. 39 */ createChild(String name)40 MetricCollector createChild(String name); 41 42 /** 43 * Return the collected metrics. The returned {@code MetricCollection} must 44 * preserve the children of this collector; in other words the tree formed 45 * by this collector and its children should be identical to the tree formed 46 * by the returned {@code MetricCollection} and its child collections. 47 * <p> 48 * Calling {@code collect()} prevents further invocations of {@link 49 * #reportMetric(SdkMetric, Object)}. 50 * 51 * @return The collected metrics. 52 */ collect()53 MetricCollection collect(); 54 create(String name)55 static MetricCollector create(String name) { 56 return DefaultMetricCollector.create(name); 57 } 58 } 59