CAMEL-9955: Uptime can now be returned as millis.

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/12f2325a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/12f2325a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/12f2325a

Branch: refs/heads/kube-lb
Commit: 12f2325a1e83e837d2e59942ba037d97024057c1
Parents: a27b45d
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri May 13 10:19:12 2016 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon May 16 09:59:33 2016 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/CamelContext.java   |  7 +++++++
 camel-core/src/main/java/org/apache/camel/Route.java   |  7 +++++++
 .../api/management/mbean/ManagedCamelContextMBean.java |  5 ++++-
 .../camel/api/management/mbean/ManagedRouteMBean.java  |  5 ++++-
 .../org/apache/camel/impl/DefaultCamelContext.java     | 12 +++++++++---
 .../main/java/org/apache/camel/impl/DefaultRoute.java  | 13 +++++++++----
 .../camel/management/mbean/ManagedCamelContext.java    |  4 ++++
 .../apache/camel/management/mbean/ManagedRoute.java    |  4 ++++
 .../management/ManagedCamelContextRestartTest.java     |  3 +++
 .../ManagedCamelContextSuspendResumeTest.java          |  3 +++
 .../ManagedCamelContextSuspendStartTest.java           |  3 +++
 .../camel/management/ManagedCamelContextTest.java      |  3 +++
 .../apache/camel/management/ManagedRouteStopTest.java  |  6 ++++++
 13 files changed, 66 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java 
b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 44b0ae1..d830e2d 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -203,6 +203,13 @@ public interface CamelContext extends SuspendableService, 
RuntimeConfiguration {
      */
     String getUptime();
 
+    /**
+     * Gets the uptime in milli seconds
+     *
+     * @return the uptime in millis seconds
+     */
+    long getUptimeMillis();
+
     // Service Methods
     //-----------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/Route.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Route.java 
b/camel-core/src/main/java/org/apache/camel/Route.java
index 31b16b1..48c6445 100644
--- a/camel-core/src/main/java/org/apache/camel/Route.java
+++ b/camel-core/src/main/java/org/apache/camel/Route.java
@@ -53,6 +53,13 @@ public interface Route extends EndpointAware {
     String getUptime();
 
     /**
+     * Gets the uptime in milli seconds
+     *
+     * @return the uptime in millis seconds
+     */
+    long getUptimeMillis();
+
+    /**
      * Gets the inbound {@link Consumer}
      *
      * @return the inbound consumer

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index d71472e..af1de0b 100644
--- 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -40,9 +40,12 @@ public interface ManagedCamelContextMBean extends 
ManagedPerformanceCounterMBean
     @ManagedAttribute(description = "Camel State")
     String getState();
 
-    @ManagedAttribute(description = "Uptime")
+    @ManagedAttribute(description = "Uptime [human readable text]")
     String getUptime();
 
+    @ManagedAttribute(description = "Uptime [milliseconds]")
+    long getUptimeMillis();
+
     @ManagedAttribute(description = "Camel Management StatisticsLevel")
     String getManagementStatisticsLevel();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java
index bdc26f7..010a6dd 100644
--- 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java
@@ -33,9 +33,12 @@ public interface ManagedRouteMBean extends 
ManagedPerformanceCounterMBean {
     @ManagedAttribute(description = "Route State")
     String getState();
 
-    @ManagedAttribute(description = "Route Uptime")
+    @ManagedAttribute(description = "Route Uptime [human readable text]")
     String getUptime();
 
+    @ManagedAttribute(description = "Route Uptime [milliseconds]")
+    long getUptimeMillis();
+
     /**
      * @deprecated use {@link #getExchangesInflight()}
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index e2b63ab..180fa99 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -2735,14 +2735,20 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
     }
 
     public String getUptime() {
-        // compute and log uptime
-        if (startDate == null) {
+        long delta = getUptimeMillis();
+        if (delta == 0) {
             return "";
         }
-        long delta = new Date().getTime() - startDate.getTime();
         return TimeUtils.printDuration(delta);
     }
 
+    public long getUptimeMillis() {
+        if (startDate == null) {
+            return 0;
+        }
+        return new Date().getTime() - startDate.getTime();
+    }
+
     @Override
     protected void doSuspend() throws Exception {
         EventHelper.notifyCamelContextSuspending(this);

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
index 2b280e7..edf9a8a 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRoute.java
@@ -67,16 +67,21 @@ public abstract class DefaultRoute extends ServiceSupport 
implements Route {
         return (String) properties.get(Route.ID_PROPERTY);
     }
 
-    @Override
     public String getUptime() {
-        // compute and log uptime
-        if (startDate == null) {
+        long delta = getUptimeMillis();
+        if (delta == 0) {
             return "";
         }
-        long delta = new Date().getTime() - startDate.getTime();
         return TimeUtils.printDuration(delta);
     }
 
+    public long getUptimeMillis() {
+        if (startDate == null) {
+            return 0;
+        }
+        return new Date().getTime() - startDate.getTime();
+    }
+
     public Endpoint getEndpoint() {
         return endpoint;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 91e7713..2c23bae 100644
--- 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -116,6 +116,10 @@ public class ManagedCamelContext extends 
ManagedPerformanceCounter implements Ti
         return context.getUptime();
     }
 
+    public long getUptimeMillis() {
+        return context.getUptimeMillis();
+    }
+
     public String getManagementStatisticsLevel() {
         if (context.getManagementStrategy().getManagementAgent() != null) {
             return 
context.getManagementStrategy().getManagementAgent().getStatisticsLevel().name();

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
index e56b024..b0be985 100644
--- 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
@@ -131,6 +131,10 @@ public class ManagedRoute extends 
ManagedPerformanceCounter implements TimerList
         return route.getUptime();
     }
 
+    public long getUptimeMillis() {
+        return route.getUptimeMillis();
+    }
+
     public Integer getInflightExchanges() {
         return (int) super.getExchangesInflight();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextRestartTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextRestartTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextRestartTest.java
index 2852cf7..c1c8093 100644
--- 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextRestartTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextRestartTest.java
@@ -75,6 +75,9 @@ public class ManagedCamelContextRestartTest extends 
ManagementTestSupport {
         String uptime = (String) mbeanServer.getAttribute(on, "Uptime");
         assertNotNull(uptime);
 
+        long uptimeMillis = (Long) mbeanServer.getAttribute(on, 
"UptimeMillis");
+        assertTrue(uptimeMillis > 0);
+
         String status = (String) mbeanServer.getAttribute(on, "State");
         assertEquals("Started", status);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendResumeTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendResumeTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendResumeTest.java
index 56ca72a..72210ab 100644
--- 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendResumeTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendResumeTest.java
@@ -44,6 +44,9 @@ public class ManagedCamelContextSuspendResumeTest extends 
ManagementTestSupport
         String uptime = (String) mbeanServer.getAttribute(on, "Uptime");
         assertNotNull(uptime);
 
+        long uptimeMillis = (Long) mbeanServer.getAttribute(on, 
"UptimeMillis");
+        assertTrue(uptimeMillis > 0);
+
         String status = (String) mbeanServer.getAttribute(on, "State");
         assertEquals("Started", status);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendStartTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendStartTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendStartTest.java
index f64ab68..4685028 100644
--- 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendStartTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextSuspendStartTest.java
@@ -44,6 +44,9 @@ public class ManagedCamelContextSuspendStartTest extends 
ManagementTestSupport {
         String uptime = (String) mbeanServer.getAttribute(on, "Uptime");
         assertNotNull(uptime);
 
+        long uptimeMillis = (Long) mbeanServer.getAttribute(on, 
"UptimeMillis");
+        assertTrue(uptimeMillis > 0);
+
         String status = (String) mbeanServer.getAttribute(on, "State");
         assertEquals("Started", status);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
index ab76a87..1a658a6 100644
--- 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
@@ -82,6 +82,9 @@ public class ManagedCamelContextTest extends 
ManagementTestSupport {
         String uptime = (String) mbeanServer.getAttribute(on, "Uptime");
         assertNotNull(uptime);
 
+        long uptimeMillis = (Long) mbeanServer.getAttribute(on, 
"UptimeMillis");
+        assertTrue(uptimeMillis > 0);
+
         String status = (String) mbeanServer.getAttribute(on, "State");
         assertEquals("Started", status);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/12f2325a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopTest.java
index 4c82293..aa5b930 100644
--- 
a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteStopTest.java
@@ -61,6 +61,9 @@ public class ManagedRouteStopTest extends 
ManagementTestSupport {
         assertNotNull(uptime);
         log.info("Uptime: {}", uptime);
 
+        long uptimeMillis = (Long) mbeanServer.getAttribute(on, 
"UptimeMillis");
+        assertTrue(uptimeMillis > 0);
+
         mbeanServer.invoke(on, "stop", null, null);
 
         registered = mbeanServer.isRegistered(on);
@@ -72,6 +75,9 @@ public class ManagedRouteStopTest extends 
ManagementTestSupport {
 
         uptime = (String) mbeanServer.getAttribute(on, "Uptime");
         assertEquals("", uptime);
+
+        uptimeMillis = (Long) mbeanServer.getAttribute(on, "UptimeMillis");
+        assertEquals(0, uptimeMillis);
     }
 
     @Override

Reply via email to