mirror of https://github.com/apache/activemq.git
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.
This commit is contained in:
parent
092c56d70c
commit
19fd084a83
|
@ -35,8 +35,8 @@ import org.apache.activemq.usage.SystemUsage;
|
||||||
|
|
||||||
public class HealthView implements HealthViewMBean {
|
public class HealthView implements HealthViewMBean {
|
||||||
|
|
||||||
ManagedRegionBroker broker;
|
private ManagedRegionBroker broker;
|
||||||
String currentState = "Good";
|
private volatile String currentState = "Good";
|
||||||
|
|
||||||
public HealthView(ManagedRegionBroker broker) {
|
public HealthView(ManagedRegionBroker broker) {
|
||||||
this.broker = broker;
|
this.broker = broker;
|
||||||
|
@ -87,6 +87,7 @@ public class HealthView implements HealthViewMBean {
|
||||||
while (dir != null && !dir.isDirectory()) {
|
while (dir != null && !dir.isDirectory()) {
|
||||||
dir = dir.getParentFile();
|
dir = dir.getParentFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
long storeSize = adapter.size();
|
long storeSize = adapter.size();
|
||||||
long storeLimit = usage.getStoreUsage().getLimit();
|
long storeLimit = usage.getStoreUsage().getLimit();
|
||||||
long dirFreeSpace = dir.getUsableSpace();
|
long dirFreeSpace = dir.getUsableSpace();
|
||||||
|
@ -166,18 +167,30 @@ public class HealthView implements HealthViewMBean {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuilder currentState = new StringBuilder();
|
||||||
if (answer != null && !answer.isEmpty()) {
|
if (answer != null && !answer.isEmpty()) {
|
||||||
this.currentState = "Getting Worried {";
|
currentState.append("Getting Worried {");
|
||||||
for (HealthStatus hs : answer) {
|
for (HealthStatus hs : answer) {
|
||||||
currentState += hs + " , ";
|
currentState.append(hs).append(" , ");
|
||||||
}
|
}
|
||||||
currentState += " }";
|
currentState.append(" }");
|
||||||
} else {
|
} else {
|
||||||
this.currentState = "Good";
|
currentState.append("Good");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.currentState = currentState.toString();
|
||||||
|
|
||||||
return answer;
|
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
|
* @return String representation of the current Broker state
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -33,13 +33,26 @@ public interface HealthViewMBean {
|
||||||
* like <a href="http://jolokia.org/">jolokia</a> to access JMX.
|
* like <a href="http://jolokia.org/">jolokia</a> to access JMX.
|
||||||
*
|
*
|
||||||
* If in doubt, please use the {@link #getCurrentStatus()} method instead!
|
* 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!")
|
@MBeanInfo("List of warnings and errors about the current health of the Broker - empty list is Good!")
|
||||||
List<HealthStatus> healthList() throws Exception;
|
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
|
* @return String representation of the current Broker state
|
||||||
*/
|
*/
|
||||||
@MBeanInfo("String representation of current Broker state")
|
@MBeanInfo("String representation of current Broker state")
|
||||||
String getCurrentStatus();
|
String getCurrentStatus();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,11 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
|
|
||||||
|
String healthStatus = health.healthStatus();
|
||||||
|
String currentStatus = health.getCurrentStatus();
|
||||||
|
|
||||||
|
assertEquals(healthStatus, currentStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObjectName assertRegisteredObjectName(String name) throws MalformedObjectNameException, NullPointerException {
|
protected ObjectName assertRegisteredObjectName(String name) throws MalformedObjectNameException, NullPointerException {
|
||||||
|
|
Loading…
Reference in New Issue