Author: chetanm
Date: Tue Jan  5 07:44:44 2016
New Revision: 1723012

URL: http://svn.apache.org/viewvc?rev=1723012&view=rev
Log:
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.

Added:
    
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/MetricsService.java
   (with props)
    
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/NoopMetric.java
   (with props)

Added: 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/MetricsService.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/MetricsService.java?rev=1723012&view=auto
==============================================================================
--- 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/MetricsService.java
 (added)
+++ 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/MetricsService.java
 Tue Jan  5 07:44:44 2016
@@ -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);
+}

Propchange: 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/MetricsService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/NoopMetric.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/NoopMetric.java?rev=1723012&view=auto
==============================================================================
--- 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/NoopMetric.java
 (added)
+++ 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/NoopMetric.java
 Tue Jan  5 07:44:44 2016
@@ -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() {
+
+        }
+    }
+}

Propchange: 
sling/whiteboard/chetanm/metrics/src/main/java/org/apache/sling/metrics/NoopMetric.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to