activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1383327 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker: BrokerService.java jmx/BrokerView.java jmx/BrokerViewMBean.java
Date Tue, 11 Sep 2012 09:51:24 GMT
Author: davsclaus
Date: Tue Sep 11 09:51:24 2012
New Revision: 1383327

URL: http://svn.apache.org/viewvc?rev=1383327&view=rev
Log:
AMQ-4015: Added uptime to broker service, and shown in JMX, as well in logs when stopping
broker.

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=1383327&r1=1383326&r2=1383327&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Tue Sep 11 09:51:24 2012
@@ -25,6 +25,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -112,6 +113,7 @@ import org.apache.activemq.util.InetAddr
 import org.apache.activemq.util.JMXSupport;
 import org.apache.activemq.util.ServiceStopper;
 import org.apache.activemq.util.ThreadPoolUtils;
+import org.apache.activemq.util.TimeUtils;
 import org.apache.activemq.util.URISupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -231,6 +233,7 @@ public class BrokerService implements Se
     private final Object persistenceAdapterLock = new Object();
     private Throwable startException = null;
     private boolean startAsync = false;
+    private Date startDate;
 
     static {
         String localHostName = "localhost";
@@ -483,6 +486,15 @@ public class BrokerService implements Se
         }
     }
 
+    public String getUptime() {
+        // compute and log uptime
+        if (startDate == null) {
+            return "not started";
+        }
+        long delta = new Date().getTime() - startDate.getTime();
+        return TimeUtils.printDuration(delta);
+    }
+
     public boolean isStarted() {
         return started.get();
     }
@@ -537,6 +549,7 @@ public class BrokerService implements Se
             return;
         }
 
+        startDate = new Date();
         MDC.put("activemq.broker", brokerName);
 
         try {
@@ -778,6 +791,9 @@ public class BrokerService implements Se
         this.destinationFactory = null;
 
         if (LOG.isInfoEnabled()) {
+            if (startDate != null) {
+                LOG.info("Uptime {}", getUptime());
+            }
             LOG.info("ActiveMQ " + getBrokerVersion() + " JMS Message Broker ("
                     + getBrokerName() + ", " + brokerId + ") stopped");
         }
@@ -794,6 +810,9 @@ public class BrokerService implements Se
 
         MDC.remove("activemq.broker");
 
+        // and clear start date
+        startDate = null;
+
         stopper.throwFirstException();
     }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java?rev=1383327&r1=1383326&r2=1383327&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java
Tue Sep 11 09:51:24 2012
@@ -79,6 +79,11 @@ public class BrokerView implements Broke
         return ActiveMQConnectionMetaData.PROVIDER_VERSION;
     }
 
+    @Override
+    public String getUptime() {
+        return brokerService.getUptime();
+    }
+
     public void gc() throws Exception {
         brokerService.getBroker().gc();
         try {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java?rev=1383327&r1=1383326&r2=1383327&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerViewMBean.java
Tue Sep 11 09:51:24 2012
@@ -47,6 +47,12 @@ public interface BrokerViewMBean extends
     String getBrokerVersion();
 
     /**
+     * @return Uptime of the broker.
+     */
+    @MBeanInfo("Uptime of the broker.")
+    String getUptime();
+
+    /**
      * The Broker will flush it's caches so that the garbage collector can
      * reclaim more memory.
      *



Mime
View raw message