This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.commons.metrics-0.0.2
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 2f3618034b25ab4f0f4cffcde28b27b3794555b5
Author: Chetan Mehrotra <[email protected]>
AuthorDate: Tue Jan 5 07:44:44 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    MetricService provides access to Metric instances. It also provides a NOOP 
variant which can be used if dependency on MetricService is to be considered 
optional.
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/whiteboard/chetanm/metrics@1723012 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/metrics/MetricsService.java   | 79 ++++++++++++++++++
 .../java/org/apache/sling/metrics/NoopMetric.java  | 94 ++++++++++++++++++++++
 2 files changed, 173 insertions(+)

diff --git a/src/main/java/org/apache/sling/metrics/MetricsService.java 
b/src/main/java/org/apache/sling/metrics/MetricsService.java
new file mode 100644
index 0000000..ab8a3b1
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/MetricsService.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.metrics;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface MetricsService {
+    MetricsService NOOP = new MetricsService() {
+        @Override
+        public Timer timer(String name) {
+            return NoopMetric.INSTANCE;
+        }
+
+        @Override
+        public Histogram histogram(String name) {
+            return NoopMetric.INSTANCE;
+        }
+
+        @Override
+        public Counter counter(String name) {
+            return NoopMetric.INSTANCE;
+        }
+
+        @Override
+        public Meter meter(String name) {
+            return NoopMetric.INSTANCE;
+        }
+    };
+
+    /**
+     * Creates a new {@link com.codahale.metrics.Timer} and registers it under 
the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link com.codahale.metrics.Timer}
+     */
+    Timer timer(String name);
+
+    /**
+     * Creates a new {@link com.codahale.metrics.Histogram} and registers it 
under the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link com.codahale.metrics.Histogram}
+     */
+    Histogram histogram(String name);
+
+    /**
+     * Creates a new {@link com.codahale.metrics.Counter} and registers it 
under the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link com.codahale.metrics.Counter}
+     */
+    Counter counter(String name);
+
+    /**
+     * Creates a new {@link com.codahale.metrics.Meter} and registers it under 
the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link com.codahale.metrics.Meter}
+     */
+    Meter meter(String name);
+}
diff --git a/src/main/java/org/apache/sling/metrics/NoopMetric.java 
b/src/main/java/org/apache/sling/metrics/NoopMetric.java
new file mode 100644
index 0000000..210fb3c
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/NoopMetric.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.metrics;
+
+import java.util.concurrent.TimeUnit;
+
+final class NoopMetric implements Counter, Histogram, Timer, Meter{
+    public static final NoopMetric INSTANCE = new NoopMetric();
+    @Override
+    public long getCount() {
+        return 0;
+    }
+
+    @Override
+    public void inc() {
+
+    }
+
+    @Override
+    public void dec() {
+
+    }
+
+    @Override
+    public void inc(long n) {
+
+    }
+
+    @Override
+    public void dec(long n) {
+
+    }
+
+    @Override
+    public void mark() {
+
+    }
+
+    @Override
+    public void mark(long n) {
+
+    }
+
+    @Override
+    public void update(long duration, TimeUnit unit) {
+
+    }
+
+    @Override
+    public Context time() {
+        return NoopContext.INSTANCE;
+    }
+
+    @Override
+    public void update(long value) {
+
+    }
+
+    @Override
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+        return null;
+    }
+
+    private static final class NoopContext implements Context {
+        public static final NoopContext INSTANCE = new NoopContext();
+
+        @Override
+        public long stop() {
+            return 0;
+        }
+
+        @Override
+        public void close() {
+
+        }
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to