polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [1/3] zest-java git commit: ZEST-190 Refine Metrics API
Date Mon, 07 Nov 2016 12:58:59 GMT
Repository: zest-java
Updated Branches:
  refs/heads/develop 420054295 -> 812f1446c


ZEST-190 Refine Metrics API

Remove reporting aspects from the Metrics API.
Use Stream<Metric> instead of Iterable in MetricsFactory::registered().


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/cd3053e7
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/cd3053e7
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/cd3053e7

Branch: refs/heads/develop
Commit: cd3053e75cef3563c9793beecc8c4ddaec671568
Parents: 4200542
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Oct 24 19:35:18 2016 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Nov 7 11:54:32 2016 +0100

----------------------------------------------------------------------
 .../apache/zest/api/metrics/MetricsFactory.java |  4 ++-
 .../zest/api/metrics/MetricsMeterFactory.java   |  6 +---
 .../zest/api/metrics/MetricsTimerFactory.java   |  6 +---
 .../zest/api/metrics/DocumentationSupport.java  |  4 +--
 .../runtime/unitofwork/UnitOfWorkInstance.java  |  5 ++-
 .../zest/spi/metrics/NullMetricsFactory.java    | 31 +++++++++---------
 .../zest/spi/metrics/DefaultMetricsTest.java    |  4 +--
 .../zest/metrics/yammer/YammerMetricsMixin.java | 34 ++++++++++----------
 .../metrics/TimingCaptureAllConcern.java        |  3 +-
 9 files changed, 44 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java
index 456f09c..175f1b6 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsFactory.java
@@ -20,10 +20,12 @@
 
 package org.apache.zest.api.metrics;
 
+import java.util.stream.Stream;
+
 /**
  * Metrics Factory.
  */
 public interface MetricsFactory
 {
-    Iterable<Metric> registered();
+    Stream<Metric> registered();
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
index ddd338a..ddafbe0 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
@@ -20,8 +20,6 @@
 
 package org.apache.zest.api.metrics;
 
-import java.util.concurrent.TimeUnit;
-
 /**
  * Create MetricsMeter instances.
  */
@@ -33,10 +31,8 @@ public interface MetricsMeterFactory extends MetricsFactory
      *
      * @param origin    The class that instantiate the metric
      * @param name      A human readable, short name of the metric.
-     * @param eventType the plural name of the event the meter is measuring (e.g., {@code
"requests"})
-     * @param rate      the scale unit for this timer's rate metrics
      *
      * @return A Metric instance to be used, OR org.apache.zest.spi.metrics.DefaultMetric.NULL
if not supported.
      */
-    MetricsMeter createMeter( Class<?> origin, String name, String eventType, TimeUnit
rate );
+    MetricsMeter createMeter( Class<?> origin, String name );
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
index accc3b8..3c015b2 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
@@ -20,8 +20,6 @@
 
 package org.apache.zest.api.metrics;
 
-import java.util.concurrent.TimeUnit;
-
 /**
  * Create MetricsTimer instances.
  */
@@ -33,11 +31,9 @@ public interface MetricsTimerFactory extends MetricsFactory
      *
      * @param origin   The class that instantiate the metric
      * @param name     A human readable, short name of the metric.
-     * @param duration the scale unit for this timer's duration metrics
-     * @param rate     the scale unit for this timer's rate metrics
      *
      * @return A Metric instance to be used, OR org.apache.zest.spi.metrics.DefaultMetric.NULL
if not supported.
      *
      */
-    MetricsTimer createTimer( Class<?> origin, String name, TimeUnit duration, TimeUnit
rate );
+    MetricsTimer createTimer( Class<?> origin, String name );
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
b/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
index dc55a91..ad71b76 100644
--- a/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
+++ b/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
@@ -61,12 +61,12 @@ public class DocumentationSupport
 
         // START SNIPPET: meter
         MetricsMeterFactory meterFactory = provider.createFactory( MetricsMeterFactory.class
);
-        MetricsMeter meter = meterFactory.createMeter( getClass(), "Sample Meter", "requests",
TimeUnit.MINUTES );
+        MetricsMeter meter = meterFactory.createMeter( getClass(), "Sample Meter" );
         // END SNIPPET: meter
 
         // START SNIPPET: timer
         MetricsTimerFactory timerFactory = provider.createFactory( MetricsTimerFactory.class
);
-        MetricsTimer timer = timerFactory.createTimer( getClass(), "Sample Timer", TimeUnit.SECONDS,
TimeUnit.HOURS );
+        MetricsTimer timer = timerFactory.createTimer( getClass(), "Sample Timer" );
         // END SNIPPET: timer
 
         // START SNIPPET: healthcheck

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
index d7ffa9d..4dca0fd 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
@@ -27,7 +27,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
-import java.util.concurrent.TimeUnit;
 import org.apache.zest.api.common.MetaInfo;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.entity.EntityDescriptor;
@@ -40,8 +39,8 @@ import org.apache.zest.api.metrics.MetricsTimerFactory;
 import org.apache.zest.api.structure.ModuleDescriptor;
 import org.apache.zest.api.type.HasTypes;
 import org.apache.zest.api.unitofwork.ConcurrentEntityModificationException;
-import org.apache.zest.api.unitofwork.NoSuchEntityTypeException;
 import org.apache.zest.api.unitofwork.NoSuchEntityException;
+import org.apache.zest.api.unitofwork.NoSuchEntityTypeException;
 import org.apache.zest.api.unitofwork.UnitOfWork;
 import org.apache.zest.api.unitofwork.UnitOfWorkCallback;
 import org.apache.zest.api.unitofwork.UnitOfWorkCompletionException;
@@ -512,7 +511,7 @@ public final class UnitOfWorkInstance
     {
         MetricsTimerFactory metricsFactory = metrics.createFactory( MetricsTimerFactory.class
);
         String name = "UnitOfWork Timer";
-        MetricsTimer timer = metricsFactory.createTimer( getClass(), name, TimeUnit.MILLISECONDS,
TimeUnit.SECONDS );
+        MetricsTimer timer = metricsFactory.createTimer( getClass(), name );
         metricsTimer = timer.start();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java b/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
index 881f252..20a0c8d 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
@@ -20,7 +20,7 @@
 
 package org.apache.zest.spi.metrics;
 
-import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
 import org.apache.zest.api.metrics.Metric;
 import org.apache.zest.api.metrics.MetricsCounter;
 import org.apache.zest.api.metrics.MetricsCounterFactory;
@@ -34,7 +34,6 @@ import org.apache.zest.api.metrics.MetricsMeter;
 import org.apache.zest.api.metrics.MetricsMeterFactory;
 import org.apache.zest.api.metrics.MetricsTimer;
 import org.apache.zest.api.metrics.MetricsTimerFactory;
-import org.apache.zest.functional.Iterables;
 
 /**
  * Factory for Metrics null objects.
@@ -50,9 +49,9 @@ public final class NullMetricsFactory
         }
 
         @Override
-        public Iterable<Metric> registered()
+        public Stream<Metric> registered()
         {
-            return Iterables.iterable( (Metric) DefaultMetric.NULL );
+            return Stream.of( DefaultMetric.NULL );
         }
     }
 
@@ -66,9 +65,9 @@ public final class NullMetricsFactory
         }
 
         @Override
-        public Iterable<Metric> registered()
+        public Stream<Metric> registered()
         {
-            return Iterables.iterable( (Metric) DefaultMetric.NULL );
+            return Stream.of( DefaultMetric.NULL );
         }
     }
 
@@ -81,9 +80,9 @@ public final class NullMetricsFactory
         }
 
         @Override
-        public Iterable<Metric> registered()
+        public Stream<Metric> registered()
         {
-            return Iterables.iterable( (Metric) DefaultMetric.NULL );
+            return Stream.of( DefaultMetric.NULL );
         }
     }
 
@@ -96,40 +95,40 @@ public final class NullMetricsFactory
         }
 
         @Override
-        public Iterable<Metric> registered()
+        public Stream<Metric> registered()
         {
-            return Iterables.iterable( (Metric) DefaultMetric.NULL );
+            return Stream.of( DefaultMetric.NULL );
         }
     }
 
     public static class NullMeterFactory implements MetricsMeterFactory
     {
         @Override
-        public MetricsMeter createMeter( Class<?> origin, String name, String eventType,
TimeUnit rate )
+        public MetricsMeter createMeter( Class<?> origin, String name )
         {
 
             return DefaultMetric.NULL;
         }
 
         @Override
-        public Iterable<Metric> registered()
+        public Stream<Metric> registered()
         {
-            return Iterables.iterable( (Metric) DefaultMetric.NULL );
+            return Stream.of( DefaultMetric.NULL );
         }
     }
 
     public static class NullTimerFactory implements MetricsTimerFactory
     {
         @Override
-        public MetricsTimer createTimer( Class<?> origin, String name, TimeUnit duration,
TimeUnit rate )
+        public MetricsTimer createTimer( Class<?> origin, String name )
         {
             return DefaultMetric.NULL;
         }
 
         @Override
-        public Iterable<Metric> registered()
+        public Stream<Metric> registered()
         {
-            return Iterables.iterable( (Metric) DefaultMetric.NULL );
+            return Stream.of( DefaultMetric.NULL );
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
----------------------------------------------------------------------
diff --git a/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java b/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
index a92d526..284c23a 100644
--- a/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
+++ b/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
@@ -102,7 +102,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsMeterFactory factory = underTest.createFactory( MetricsMeterFactory.class
);
-        MetricsMeter test = factory.createMeter( getClass(), "test", "niclas", TimeUnit.MILLISECONDS
);
+        MetricsMeter test = factory.createMeter( getClass(), "test" );
         test.mark();
         test.mark();
         test.mark();
@@ -113,7 +113,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsTimerFactory factory = underTest.createFactory( MetricsTimerFactory.class
);
-        MetricsTimer test = factory.createTimer( getClass(), "test", TimeUnit.MILLISECONDS,
TimeUnit.DAYS );
+        MetricsTimer test = factory.createTimer( getClass(), "test" );
         test.start().stop();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
----------------------------------------------------------------------
diff --git a/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
b/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
index c40adc3..be92066 100644
--- a/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
+++ b/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
@@ -24,6 +24,7 @@ import com.yammer.metrics.Metrics;
 import com.yammer.metrics.core.Counter;
 import com.yammer.metrics.core.Gauge;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
 import org.apache.zest.api.injection.scope.Structure;
 import org.apache.zest.api.metrics.Metric;
 import org.apache.zest.api.metrics.MetricsCounter;
@@ -39,7 +40,6 @@ import org.apache.zest.api.metrics.MetricsMeterFactory;
 import org.apache.zest.api.metrics.MetricsTimer;
 import org.apache.zest.api.metrics.MetricsTimerFactory;
 import org.apache.zest.api.structure.Application;
-import org.apache.zest.functional.Iterables;
 import org.apache.zest.spi.metrics.MetricsProviderAdapter;
 
 public class YammerMetricsMixin extends MetricsProviderAdapter
@@ -54,15 +54,15 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsTimerFactory()
         {
             @Override
-            public MetricsTimer createTimer( Class<?> origin, String name, TimeUnit
duration, TimeUnit rate )
+            public MetricsTimer createTimer( Class<?> origin, String name )
             {
-                return new YammerTimer( Metrics.newTimer( origin, name, app.name(), duration,
rate ) );
+                return new YammerTimer( Metrics.newTimer( origin, name, app.name(), TimeUnit.MILLISECONDS,
TimeUnit.SECONDS ) );
             }
 
             @Override
-            public Iterable<Metric> registered()
+            public Stream<Metric> registered()
             {
-                return Iterables.empty();
+                return Stream.empty();
             }
         };
     }
@@ -73,15 +73,15 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsMeterFactory()
         {
             @Override
-            public MetricsMeter createMeter( Class<?> origin, String name, String eventType,
TimeUnit rate )
+            public MetricsMeter createMeter( Class<?> origin, String name )
             {
-                return new YammerMeter( Metrics.newMeter( origin, name, app.name(), eventType,
rate ) );
+                return new YammerMeter( Metrics.newMeter( origin, name, app.name(), TimeUnit.MILLISECONDS
) );
             }
 
             @Override
-            public Iterable<Metric> registered()
+            public Stream<Metric> registered()
             {
-                return Iterables.empty();
+                return Stream.empty();
             }
         };
     }
@@ -98,9 +98,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
             }
 
             @Override
-            public Iterable<Metric> registered()
+            public Stream<Metric> registered()
             {
-                return Iterables.empty();
+                return Stream.empty();
             }
         };
     }
@@ -117,9 +117,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
             }
 
             @Override
-            public Iterable<Metric> registered()
+            public Stream<Metric> registered()
             {
-                return Iterables.empty();
+                return Stream.empty();
             }
         };
     }
@@ -145,9 +145,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
             }
 
             @Override
-            public Iterable<Metric> registered()
+            public Stream<Metric> registered()
             {
-                return Iterables.empty();
+                return Stream.empty();
             }
         };
     }
@@ -165,9 +165,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
             }
 
             @Override
-            public Iterable<Metric> registered()
+            public Stream<Metric> registered()
             {
-                return Iterables.empty();
+                return Stream.empty();
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/cd3053e7/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
----------------------------------------------------------------------
diff --git a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
index c312d14..015f1d8 100644
--- a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
+++ b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
@@ -22,7 +22,6 @@ package org.apache.zest.library.metrics;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.util.concurrent.TimeUnit;
 import org.apache.zest.api.common.Optional;
 import org.apache.zest.api.concern.ConcernOf;
 import org.apache.zest.api.injection.scope.Invocation;
@@ -46,7 +45,7 @@ public class TimingCaptureAllConcern extends ConcernOf<InvocationHandler>
             boolean annotated = method.getAnnotation( TimingCapture.class ) != null;
             String captureNme = getMethodName( method ) + "() ["  +( annotated ? "@" : ""
) + "TimingCapture" + "]";
             Class<?> declaringClass = method.getDeclaringClass();
-            timer = factory.createTimer( declaringClass, captureNme, TimeUnit.MILLISECONDS,
TimeUnit.SECONDS );
+            timer = factory.createTimer( declaringClass, captureNme );
         }
     }
 


Mime
View raw message