You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/08/07 05:00:11 UTC

svn commit: r1154644 - in /activemq/activemq-apollo/trunk: apollo-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala

Author: chirino
Date: Sun Aug  7 03:00:11 2011
New Revision: 1154644

URL: http://svn.apache.org/viewvc?rev=1154644&view=rev
Log:
Exposing helper details a little more.

Modified:
    activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala

Modified: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala?rev=1154644&r1=1154643&r2=1154644&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/TimeCounter.scala Sun Aug  7 03:00:11 2011
@@ -25,10 +25,10 @@ import java.util.concurrent.TimeUnit
  */
 class TimeCounter extends MetricProducer[TimeMetric] {
 
-  private var max = Long.MinValue
-  private var min = Long.MaxValue
-  private var total = 0L
-  private var count = 0
+  var max = Long.MinValue
+  var min = Long.MaxValue
+  var total = 0L
+  var count = 0
 
   def apply(reset: Boolean):TimeMetric = {
     val rc = if(count==0) {
@@ -84,6 +84,10 @@ class TimeCounter extends MetricProducer
     }
     func(endFunc)
   }
+
+  def total(unit:TimeUnit):Long = {
+    TimeUnit.NANOSECONDS.convert(total, unit)
+  }
 }
 
 case class TimeMetric(count:Int, total:Long, min:Long, max:Long) {

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala?rev=1154644&r1=1154643&r2=1154644&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala Sun Aug  7 03:00:11 2011
@@ -318,7 +318,7 @@ abstract class Resource(parent:Resource=
 
 }
 
-object ViewHelper {
+object ViewHelper extends ViewHelper {
 
   val KB: Long = 1024
   val MB: Long = KB * 1024
@@ -370,23 +370,24 @@ class ViewHelper {
     }
   }
 
-  def uptime(value:Long):String = {
-    def friendly(duration:Long):String = {
-      if( duration < SECONDS ) {
-        "%d ms".format(duration)
-      } else if (duration < MINUTES) {
-        "%d seconds".format(duration / SECONDS)
-      } else if (duration < HOURS) {
-        "%d minutes".format(duration / MINUTES)
-      } else if (duration < DAYS) {
-        "%d hours %s".format(duration / HOURS, friendly(duration%HOURS))
-      } else if (duration < YEARS) {
-        "%d days %s".format(duration / DAYS, friendly(duration%DAYS))
-      } else {
-        "%,d years %s".format(duration / YEARS, friendly(duration%YEARS))
-      }
+  def friendly_duration(duration:Long):String = {
+    if( duration < SECONDS ) {
+      "%d ms".format(duration)
+    } else if (duration < MINUTES) {
+      "%d seconds".format(duration / SECONDS)
+    } else if (duration < HOURS) {
+      "%d minutes".format(duration / MINUTES)
+    } else if (duration < DAYS) {
+      "%d hours %s".format(duration / HOURS, friendly_duration(duration%HOURS))
+    } else if (duration < YEARS) {
+      "%d days %s".format(duration / DAYS, friendly_duration(duration%DAYS))
+    } else {
+      "%,d years %s".format(duration / YEARS, friendly_duration(duration%YEARS))
     }
-    friendly(System.currentTimeMillis - value)
+  }
+
+  def uptime(value:Long):String = {
+    friendly_duration(System.currentTimeMillis - value)
   }
 }