1
15 package com.amazonaws.services.s3.metrics;
16
17 import com.amazonaws.metrics.ServiceMetricType;
18 import com.amazonaws.metrics.SimpleMetricType;
19 import com.amazonaws.metrics.ThroughputMetricType;
20 import com.amazonaws.services.s3.internal.Constants;
21
22
28 public class S3ServiceMetric extends SimpleMetricType implements ServiceMetricType {
29 static final String SERVICE_NAME_PREFIX = "S3";
30
31
35 private static final String metricName(String suffix) {
36 return SERVICE_NAME_PREFIX + suffix;
37 }
38
39 public static final S3ThroughputMetric S3DownloadThroughput = new S3ThroughputMetric(
40 metricName(DOWNLOAD_THROUGHPUT_NAME_SUFFIX)) {
41 @Override
42 public ServiceMetricType getByteCountMetricType() {
43 return S3DownloadByteCount;
44 }
45 };
46 public static final S3ServiceMetric S3DownloadByteCount = new S3ServiceMetric(
47 metricName(DOWNLOAD_BYTE_COUNT_NAME_SUFFIX));
48 public static final S3ThroughputMetric S3UploadThroughput = new S3ThroughputMetric(
49 metricName(UPLOAD_THROUGHPUT_NAME_SUFFIX)) {
50 @Override
51 public ServiceMetricType getByteCountMetricType() {
52 return S3UploadByteCount;
53 }
54 };
55 public static final S3ServiceMetric S3UploadByteCount = new S3ServiceMetric(
56 metricName(UPLOAD_BYTE_COUNT_NAME_SUFFIX));
57 private static final S3ServiceMetric[] values = {
58 S3DownloadThroughput,
59 S3DownloadByteCount,
60 S3UploadThroughput,
61 S3UploadByteCount
62 };
63
64 private final String name;
65 private S3ServiceMetric(String name) { this.name = name; }
66 @Override public String name() { return name; }
67 @Override public String getServiceName() {
68 return Constants.S3_SERVICE_DISPLAY_NAME;
69 }
70
71 private static abstract class S3ThroughputMetric extends S3ServiceMetric
72 implements ThroughputMetricType {
73 private S3ThroughputMetric(String name) {
74 super(name);
75 }
76 };
77
78 public static S3ServiceMetric[] values() { return values.clone(); }
79 public static S3ServiceMetric valueOf(String name) {
80 for (S3ServiceMetric e: values()) {
81 if (e.name().equals(name)) {
82 return e;
83 }
84 }
85 throw new IllegalArgumentException("No S3ServiceMetric defined for the name "+ name);
86 }
87 }
88