activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1064201 - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
Date Thu, 27 Jan 2011 17:12:22 GMT
Author: chirino
Date: Thu Jan 27 17:12:22 2011
New Revision: 1064201

URL: http://svn.apache.org/viewvc?rev=1064201&view=rev
Log:
move the hawtdispatch monitoring feature into the broker module.

Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
    activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1064201&r1=1064200&r2=1064201&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
Thu Jan 27 17:12:22 2011
@@ -16,24 +16,22 @@
  */
 package org.apache.activemq.apollo.broker
 
-import _root_.java.io.{File}
-import _root_.java.lang.{String}
+import _root_.java.io.File
+import _root_.java.lang.String
 import org.fusesource.hawtdispatch._
-import _root_.org.fusesource.hawtdispatch.ScalaDispatchHelpers._
-import org.fusesource.hawtdispatch.{Dispatch}
+import org.fusesource.hawtdispatch.Dispatch
 import org.fusesource.hawtbuf._
 import AsciiBuffer._
-import collection.{JavaConversions, SortedMap}
+import collection.JavaConversions
 import JavaConversions._
-import org.apache.activemq.apollo.dto.{VirtualHostStatusDTO, ConnectorStatusDTO, BrokerStatusDTO,
BrokerDTO}
+import org.apache.activemq.apollo.dto.BrokerDTO
 import java.util.concurrent.atomic.AtomicLong
 import org.apache.activemq.apollo.util._
 import ReporterLevel._
-import collection.mutable.LinkedHashMap
-import java.util.concurrent.{ThreadFactory, Executors, ConcurrentHashMap}
 import security.{AclAuthorizer, Authorizer, JaasAuthenticator, Authenticator}
 import java.net.InetSocketAddress
 import org.apache.activemq.apollo.broker.web._
+import collection.mutable.{HashSet, LinkedHashMap}
 
 /**
  * <p>
@@ -89,18 +87,59 @@ object BufferConversions {
  *
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
-object BrokerRegistry {
+object BrokerRegistry extends Log {
 
-  val brokers = new ConcurrentHashMap[Broker, Broker]()
+  private val brokers = HashSet[Broker]()
 
-  def list():Array[Broker] = {
-    import JavaConversions._
-    brokers.keySet.toSeq.toArray
+  @volatile
+  private var monitor_session = 0
+
+  def list():Array[Broker] = this.synchronized {
+    brokers.toArray
+  }
+
+  def add(broker:Broker) = this.synchronized {
+    val rc = brokers.add(broker)
+    if(rc && brokers.size==1 && java.lang.Boolean.getBoolean("hawtdispatch.profile"))
{
+      // start monitoring when the first broker starts..
+      monitor_session += 1
+      monitor_hawtdispatch(monitor_session)
+    }
+    rc
+  }
+
+  def remove(broker:Broker) = this.synchronized {
+    val rc = brokers.remove(broker)
+    if(rc && brokers.size==0 && java.lang.Boolean.getBoolean("hawtdispatch.profile"))
{
+      // stomp monitoring when the last broker stops..
+      monitor_session += 1
+    }
+    rc
   }
 
-  def add(broker:Broker) = brokers.put(broker, broker)
 
-  def remove(broker:Broker) = brokers.remove(broker)
+  def monitor_hawtdispatch(session_id:Int):Unit = {
+
+    import collection.JavaConversions._
+    import java.util.concurrent.TimeUnit._
+    getGlobalQueue().after(1, SECONDS) {
+      if( session_id == monitor_session ) {
+        val m = Dispatch.metrics.toList.flatMap{x=>
+          if( x.totalWaitTimeNS > MILLISECONDS.toNanos(10) ||  x.totalRunTimeNS > MILLISECONDS.toNanos(10)
) {
+            Some(x)
+          } else {
+            None
+          }
+        }
+
+        if( !m.isEmpty ) {
+          info("-- hawtdispatch metrics -----------------------\n"+m.mkString("\n"))
+        }
+
+        monitor_hawtdispatch(session_id)
+      }
+    }
+  }
 
 }
 

Modified: activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala?rev=1064201&r1=1064200&r2=1064201&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
Thu Jan 27 17:12:22 2011
@@ -120,10 +120,6 @@ class Run extends Action with Logging {
       })
       broker.tmp = tmp
 
-      if(java.lang.Boolean.getBoolean("hawtdispatch.profile")) {
-        monitor_hawtdispatch
-      }
-
       // wait forever...  broker will system exit.
       this.synchronized {
         this.wait
@@ -136,30 +132,4 @@ class Run extends Action with Logging {
     null
   }
 
-
-  def monitor_hawtdispatch = {
-    new Thread("HawtDispatch Monitor") {
-      setDaemon(true);
-      override def run = {
-        while(true) {
-          Thread.sleep(1000);
-          import collection.JavaConversions._
-
-          // Only display is we see some long wait or run times..
-          val m = Dispatch.metrics.toList.flatMap{x=>
-            if( x.totalWaitTimeNS > 1000000 ||  x.totalRunTimeNS > 1000000 ) {
-              Some(x)
-            } else {
-              None
-            }
-          }
-
-          if( !m.isEmpty ) {
-            info("-- hawtdispatch metrics -----------------------\n"+m.mkString("\n"))
-          }
-        }
-      }
-    }.start();
-  }
-
 }



Mime
View raw message