Repository: activemq Updated Branches: refs/heads/master 092c56d70 -> 19fd084a8
https://issues.apache.org/jira/browse/AMQ-6252 Update for some added thread safety. Adds method healthStatus that will regenrate the status from the healthList data which is more intuitive than the getCurrentStatus which doesn't update state and requires periodic calls to healthList to capture current metrics. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/19fd084a Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/19fd084a Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/19fd084a Branch: refs/heads/master Commit: 19fd084a83c990f9fb75a5f2becb48ac808a1b36 Parents: 092c56d Author: Timothy Bish <[email protected]> Authored: Thu Apr 14 16:43:55 2016 -0400 Committer: Timothy Bish <[email protected]> Committed: Thu Apr 14 16:53:17 2016 -0400 ---------------------------------------------------------------------- .../apache/activemq/broker/jmx/HealthView.java | 25 +++++++++++++++----- .../activemq/broker/jmx/HealthViewMBean.java | 13 ++++++++++ .../broker/jmx/HealthViewMBeanTest.java | 5 ++++ 3 files changed, 37 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/19fd084a/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 2b6341a..47a153e 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 @@ -35,8 +35,8 @@ import org.apache.activemq.usage.SystemUsage; public class HealthView implements HealthViewMBean { - ManagedRegionBroker broker; - String currentState = "Good"; + private ManagedRegionBroker broker; + private volatile String currentState = "Good"; public HealthView(ManagedRegionBroker broker) { this.broker = broker; @@ -87,6 +87,7 @@ public class HealthView implements HealthViewMBean { while (dir != null && !dir.isDirectory()) { dir = dir.getParentFile(); } + long storeSize = adapter.size(); long storeLimit = usage.getStoreUsage().getLimit(); long dirFreeSpace = dir.getUsableSpace(); @@ -166,18 +167,30 @@ public class HealthView implements HealthViewMBean { } } + StringBuilder currentState = new StringBuilder(); if (answer != null && !answer.isEmpty()) { - this.currentState = "Getting Worried {"; + currentState.append("Getting Worried {"); for (HealthStatus hs : answer) { - currentState += hs + " , "; + currentState.append(hs).append(" , "); } - currentState += " }"; + currentState.append(" }"); } else { - this.currentState = "Good"; + currentState.append("Good"); } + + this.currentState = currentState.toString(); + return answer; } + @Override + public String healthStatus() throws Exception { + // Must invoke healthList in order to update state. + healthList(); + + return getCurrentStatus(); + } + /** * @return String representation of the current Broker state */ http://git-wip-us.apache.org/repos/asf/activemq/blob/19fd084a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthViewMBean.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthViewMBean.java index 2adf140..32fe95b 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthViewMBean.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/HealthViewMBean.java @@ -33,13 +33,26 @@ public interface HealthViewMBean { * like <a href="http://jolokia.org/">jolokia</a> to access JMX. * * If in doubt, please use the {@link #getCurrentStatus()} method instead! + * + * @return a list of HealthStatus objects that describe the health of the Broker. */ @MBeanInfo("List of warnings and errors about the current health of the Broker - empty list is Good!") List<HealthStatus> healthList() throws Exception; /** + * @return a String representation of current Broker health state. + */ + @MBeanInfo("String representation of current Broker state") + String healthStatus() throws Exception; + + /** + * Warning, this method only return a value if the health or healthList method has previously + * been called. The value is not updated on its own and requires periodic calls to the health + * or healthList methods to refresh its value. + * * @return String representation of the current Broker state */ @MBeanInfo("String representation of current Broker state") String getCurrentStatus(); + } http://git-wip-us.apache.org/repos/asf/activemq/blob/19fd084a/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 18eb0c7..e47ca0d 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 @@ -104,6 +104,11 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport { } assertEquals(2, list.size()); + + String healthStatus = health.healthStatus(); + String currentStatus = health.getCurrentStatus(); + + assertEquals(healthStatus, currentStatus); } protected ObjectName assertRegisteredObjectName(String name) throws MalformedObjectNameException, NullPointerException {
