Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-dev 0714b1100 -> 34fd9cf33


Removes redundant logic in metrics factory


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/34fd9cf3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/34fd9cf3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/34fd9cf3

Branch: refs/heads/two-dot-o-dev
Commit: 34fd9cf334b727aac4646c545ebefcb734845306
Parents: 0714b11
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Apr 22 14:45:59 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Apr 22 14:45:59 2015 -0600

----------------------------------------------------------------------
 .../core/metrics/MetricsFactoryImpl.java        | 44 ++------------------
 1 file changed, 4 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/34fd9cf3/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/metrics/MetricsFactoryImpl.java
----------------------------------------------------------------------
diff --git 
a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/metrics/MetricsFactoryImpl.java
 
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/metrics/MetricsFactoryImpl.java
index 904e56a..b068782 100644
--- 
a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/metrics/MetricsFactoryImpl.java
+++ 
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/metrics/MetricsFactoryImpl.java
@@ -49,7 +49,6 @@ public class MetricsFactoryImpl implements MetricsFactory {
     private MetricRegistry registry;
     private GraphiteReporter graphiteReporter;
     private JmxReporter jmxReporter;
-    private ConcurrentHashMap<String, Metric> hashMap;
     private static final Logger LOG = LoggerFactory.getLogger( 
MetricsFactoryImpl.class );
 
 
@@ -68,7 +67,6 @@ public class MetricsFactoryImpl implements MetricsFactory {
         else {
             LOG.warn( "MetricsService:Logger not started." );
         }
-        hashMap = new ConcurrentHashMap<String, Metric>();
 
         jmxReporter = JmxReporter.forRegistry( registry ).build();
         jmxReporter.start();
@@ -83,25 +81,25 @@ public class MetricsFactoryImpl implements MetricsFactory {
 
     @Override
     public Timer getTimer( Class<?> klass, String name ) {
-        return getMetric( Timer.class, klass, name );
+        return getRegistry().timer( MetricRegistry.name( klass, name ) );
     }
 
 
     @Override
     public Histogram getHistogram( Class<?> klass, String name ) {
-        return getMetric( Histogram.class, klass, name );
+        return getRegistry().histogram( MetricRegistry.name( klass, name ) );
     }
 
 
     @Override
     public Counter getCounter( Class<?> klass, String name ) {
-        return getMetric( Counter.class, klass, name );
+        return getRegistry().counter( MetricRegistry.name( klass, name ) );
     }
 
 
     @Override
     public Meter getMeter( Class<?> klass, String name ) {
-        return getMetric( Meter.class, klass, name );
+        return getRegistry().meter( MetricRegistry.name( klass, name ) );
     }
 
 
@@ -112,38 +110,4 @@ public class MetricsFactoryImpl implements MetricsFactory {
     }
 
 
-    private <T> T getMetric( Class<T> metricClass, Class<?> klass, String name 
) {
-        String key = metricClass.getName() + klass.getName() + name;
-        Metric metric = hashMap.get( key );
-        if ( metric == null ) {
-            if ( metricClass == Histogram.class ) {
-                metric = this.getRegistry().histogram( MetricRegistry.name( 
klass, name ) );
-            }
-            if ( metricClass == Timer.class ) {
-                metric = this.getRegistry().timer( MetricRegistry.name( klass, 
name ) );
-            }
-            if ( metricClass == Meter.class ) {
-                metric = this.getRegistry().meter( MetricRegistry.name( klass, 
name ) );
-            }
-            if ( metricClass == Counter.class ) {
-                metric = this.getRegistry().counter( MetricRegistry.name( 
klass, name ) );
-            }
-
-
-            hashMap.put( key, metric );
-        }
-        return ( T ) metric;
-    }
-
-
-    /**
-     *
-     * @param metricClass
-     * @param klass
-     * @param name
-     * @return
-     */
-    private String getKey( Class<?> metricClass, Class<?> klass, String name ) 
{
-        return metricClass.getName() + klass.getName() + name;
-    }
 }

Reply via email to