activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject git commit: https://issues.apache.org/jira/browse/AMQ-5140
Date Mon, 05 May 2014 20:13:00 GMT
Repository: activemq
Updated Branches:
  refs/heads/trunk 53b12820c -> 541ed8cf0


https://issues.apache.org/jira/browse/AMQ-5140

Add some checks to prevent any chance of an ArithmaticException because
of divide by zero. 

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/541ed8cf
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/541ed8cf
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/541ed8cf

Branch: refs/heads/trunk
Commit: 541ed8cf0c3fbe0dd4346253d22a08c4ddae5c12
Parents: 53b1282
Author: Timothy Bish <tabish121@gmai.com>
Authored: Mon May 5 16:12:50 2014 -0400
Committer: Timothy Bish <tabish121@gmai.com>
Committed: Mon May 5 16:12:50 2014 -0400

----------------------------------------------------------------------
 .../apache/activemq/broker/jmx/HealthView.java  | 62 +++++++++-----------
 .../broker/jmx/HealthViewMBeanTest.java         |  6 ++
 2 files changed, 33 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/541ed8cf/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthView.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthView.java
b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthView.java
index 4dc890b..2b6341a 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthView.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthView.java
@@ -27,6 +27,7 @@ import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.TabularData;
 import javax.management.openmbean.TabularDataSupport;
 import javax.management.openmbean.TabularType;
+
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.scheduler.JobSchedulerStore;
 import org.apache.activemq.store.PersistenceAdapter;
@@ -45,7 +46,7 @@ public class HealthView implements HealthViewMBean {
     public TabularData health() throws Exception {
         OpenTypeSupport.OpenTypeFactory factory = OpenTypeSupport.getFactory(HealthStatus.class);
         CompositeType ct = factory.getCompositeType();
-        TabularType tt = new TabularType("HealthStatus", "HealthStatus", ct, new String[]{"healthId",
"level", "message", "resource"});
+        TabularType tt = new TabularType("HealthStatus", "HealthStatus", ct, new String[]
{ "healthId", "level", "message", "resource" });
         TabularDataSupport rc = new TabularDataSupport(tt);
 
         List<HealthStatus> list = healthList();
@@ -70,7 +71,6 @@ public class HealthView implements HealthViewMBean {
 
         /**
          * Check persistence store directory limits
-         *
          */
         BrokerService brokerService = broker.getBrokerService();
         if (brokerService != null && brokerService.getPersistenceAdapter() != null)
{
@@ -84,7 +84,6 @@ public class HealthView implements HealthViewMBean {
                         dir = new File(dirPath);
                     }
 
-
                     while (dir != null && !dir.isDirectory()) {
                         dir = dir.getParentFile();
                     }
@@ -92,23 +91,21 @@ public class HealthView implements HealthViewMBean {
                     long storeLimit = usage.getStoreUsage().getLimit();
                     long dirFreeSpace = dir.getUsableSpace();
 
-                    if (storeSize != 0) {
+                    if (storeSize != 0 && storeLimit != 0) {
                         int val = (int) ((storeSize * 100) / storeLimit);
                         if (val > 90) {
-                            answer.add(new HealthStatus("org.apache.activemq.StoreLimit",
"WARNING", "Message Store size is within " + val + "% of its limit", adapter.toString()));
+                            answer.add(new HealthStatus("org.apache.activemq.StoreLimit",
"WARNING", "Message Store size is within " + val + "% of its limit",
+                                adapter.toString()));
                         }
                     }
 
-
                     if ((storeLimit - storeSize) > dirFreeSpace) {
-                        String message = "Store limit is " + storeLimit / (1024 * 1024) +
-                                " mb, whilst the data directory: " + dir.getAbsolutePath()
+
-                                " only has " + dirFreeSpace / (1024 * 1024) + " mb of usable
space";
+                        String message = "Store limit is " + storeLimit / (1024 * 1024) +
" mb, whilst the data directory: " + dir.getAbsolutePath()
+                            + " only has " + dirFreeSpace / (1024 * 1024) + " mb of usable
space";
                         answer.add(new HealthStatus("org.apache.activemq.FreeDiskSpaceLeft",
"WARNING", message, adapter.toString()));
                     }
-
-
                 }
+
                 File tmpDir = brokerService.getTmpDataDirectory();
                 if (tmpDir != null) {
 
@@ -123,15 +120,14 @@ public class HealthView implements HealthViewMBean {
                         tmpDir = tmpDir.getParentFile();
                     }
 
-                    int val = (int) ((storeSize * 100) / storeLimit);
-                    if (val > 90) {
-                        answer.add(new HealthStatus("org.apache.activemq.TempStoreLimit",
"WARNING", "TempMessage Store size is within " + val + "% of its limit", adapter.toString()));
+                    if (storeLimit != 0) {
+                        int val = (int) ((storeSize * 100) / storeLimit);
+                        if (val > 90) {
+                            answer.add(new HealthStatus("org.apache.activemq.TempStoreLimit",
"WARNING", "TempMessage Store size is within " + val
+                                + "% of its limit", adapter.toString()));
+                        }
                     }
-
-
                 }
-
-
             }
         }
 
@@ -146,7 +142,6 @@ public class HealthView implements HealthViewMBean {
                         dir = new File(dirPath);
                     }
 
-
                     while (dir != null && !dir.isDirectory()) {
                         dir = dir.getParentFile();
                     }
@@ -154,34 +149,32 @@ public class HealthView implements HealthViewMBean {
                     long storeLimit = usage.getJobSchedulerUsage().getLimit();
                     long dirFreeSpace = dir.getUsableSpace();
 
-                    if (storeSize != 0) {
+                    if (storeSize != 0 && storeLimit != 0) {
                         int val = (int) ((storeSize * 100) / storeLimit);
                         if (val > 90) {
-                            answer.add(new HealthStatus("org.apache.activemq.JobSchedulerLimit",
"WARNING", "JobSchedulerMessage Store size is within " + val + "% of its limit", scheduler.toString()));
+                            answer.add(new HealthStatus("org.apache.activemq.JobSchedulerLimit",
"WARNING", "JobSchedulerMessage Store size is within " + val
+                                + "% of its limit", scheduler.toString()));
                         }
                     }
 
-
                     if ((storeLimit - storeSize) > dirFreeSpace) {
-                        String message = "JobSchedulerStore limit is " + storeLimit / (1024
* 1024) +
-                                " mb, whilst the data directory: " + dir.getAbsolutePath()
+
-                                " only has " + dirFreeSpace / (1024 * 1024) + " mb of usable
space";
+                        String message = "JobSchedulerStore limit is " + storeLimit / (1024
* 1024) + " mb, whilst the data directory: "
+                            + dir.getAbsolutePath() + " only has " + dirFreeSpace / (1024
* 1024) + " mb of usable space";
                         answer.add(new HealthStatus("org.apache.activemq.FreeDiskSpaceLeft",
"WARNING", message, scheduler.toString()));
                     }
-
                 }
             }
         }
 
-    if (answer != null && !answer.isEmpty()){
-         this.currentState = "Getting Worried {";
-        for (HealthStatus hs: answer){
-            currentState += hs + " , ";
+        if (answer != null && !answer.isEmpty()) {
+            this.currentState = "Getting Worried {";
+            for (HealthStatus hs : answer) {
+                currentState += hs + " , ";
+            }
+            currentState += " }";
+        } else {
+            this.currentState = "Good";
         }
-        currentState += " }";
-    } else{
-        this.currentState="Good";
-    }
         return answer;
     }
 
@@ -192,5 +185,4 @@ public class HealthView implements HealthViewMBean {
     public String getCurrentStatus() {
         return this.currentState;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/541ed8cf/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
index bd6dbc2..9998be9 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
@@ -28,6 +28,7 @@ import javax.management.MBeanServer;
 import javax.management.MBeanServerInvocationHandler;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
+
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.EmbeddedBrokerTestSupport;
 import org.apache.activemq.broker.BrokerService;
@@ -39,6 +40,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
     protected MBeanServer mbeanServer;
     protected String domain = "org.apache.activemq";
 
+    @Override
     protected void setUp() throws Exception {
         bindAddress = "tcp://localhost:0";
         useTopic = false;
@@ -46,6 +48,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
         mbeanServer = broker.getManagementContext().getMBeanServer();
     }
 
+    @Override
     protected void tearDown() throws Exception {
         super.tearDown();
     }
@@ -55,6 +58,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
         return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
     }
 
+    @Override
     protected BrokerService createBroker() throws Exception {
         BrokerService answer = new BrokerService();
         answer.setPersistent(true);
@@ -63,6 +67,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
         answer.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 64);
         answer.getSystemUsage().getStoreUsage().setLimit(1024 * 1024 * 64);
         answer.setUseJmx(true);
+        answer.setSchedulerSupport(true);
 
         // allow options to be visible via jmx
 
@@ -84,6 +89,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
             message.writeBytes(new byte[1024 *1024]);
             producer.send(message);
         }
+
         Thread.sleep(1000);
 
         String objectNameStr = broker.getBrokerObjectName().toString();


Mime
View raw message