mirror of https://github.com/apache/activemq.git
AMQ-4015: Added uptime to broker service, and shown in JMX, as well in logs when stopping broker.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1383327 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
49bb4bf494
commit
f2225c2f12
|
@ -25,6 +25,7 @@ import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -112,6 +113,7 @@ import org.apache.activemq.util.InetAddressUtil;
|
||||||
import org.apache.activemq.util.JMXSupport;
|
import org.apache.activemq.util.JMXSupport;
|
||||||
import org.apache.activemq.util.ServiceStopper;
|
import org.apache.activemq.util.ServiceStopper;
|
||||||
import org.apache.activemq.util.ThreadPoolUtils;
|
import org.apache.activemq.util.ThreadPoolUtils;
|
||||||
|
import org.apache.activemq.util.TimeUtils;
|
||||||
import org.apache.activemq.util.URISupport;
|
import org.apache.activemq.util.URISupport;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -231,6 +233,7 @@ public class BrokerService implements Service {
|
||||||
private final Object persistenceAdapterLock = new Object();
|
private final Object persistenceAdapterLock = new Object();
|
||||||
private Throwable startException = null;
|
private Throwable startException = null;
|
||||||
private boolean startAsync = false;
|
private boolean startAsync = false;
|
||||||
|
private Date startDate;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String localHostName = "localhost";
|
String localHostName = "localhost";
|
||||||
|
@ -483,6 +486,15 @@ public class BrokerService implements Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
public boolean isStarted() {
|
||||||
return started.get();
|
return started.get();
|
||||||
}
|
}
|
||||||
|
@ -537,6 +549,7 @@ public class BrokerService implements Service {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startDate = new Date();
|
||||||
MDC.put("activemq.broker", brokerName);
|
MDC.put("activemq.broker", brokerName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -778,6 +791,9 @@ public class BrokerService implements Service {
|
||||||
this.destinationFactory = null;
|
this.destinationFactory = null;
|
||||||
|
|
||||||
if (LOG.isInfoEnabled()) {
|
if (LOG.isInfoEnabled()) {
|
||||||
|
if (startDate != null) {
|
||||||
|
LOG.info("Uptime {}", getUptime());
|
||||||
|
}
|
||||||
LOG.info("ActiveMQ " + getBrokerVersion() + " JMS Message Broker ("
|
LOG.info("ActiveMQ " + getBrokerVersion() + " JMS Message Broker ("
|
||||||
+ getBrokerName() + ", " + brokerId + ") stopped");
|
+ getBrokerName() + ", " + brokerId + ") stopped");
|
||||||
}
|
}
|
||||||
|
@ -794,6 +810,9 @@ public class BrokerService implements Service {
|
||||||
|
|
||||||
MDC.remove("activemq.broker");
|
MDC.remove("activemq.broker");
|
||||||
|
|
||||||
|
// and clear start date
|
||||||
|
startDate = null;
|
||||||
|
|
||||||
stopper.throwFirstException();
|
stopper.throwFirstException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,11 @@ public class BrokerView implements BrokerViewMBean {
|
||||||
return ActiveMQConnectionMetaData.PROVIDER_VERSION;
|
return ActiveMQConnectionMetaData.PROVIDER_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUptime() {
|
||||||
|
return brokerService.getUptime();
|
||||||
|
}
|
||||||
|
|
||||||
public void gc() throws Exception {
|
public void gc() throws Exception {
|
||||||
brokerService.getBroker().gc();
|
brokerService.getBroker().gc();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -46,6 +46,12 @@ public interface BrokerViewMBean extends Service {
|
||||||
@MBeanInfo("The version of the broker.")
|
@MBeanInfo("The version of the broker.")
|
||||||
String getBrokerVersion();
|
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
|
* The Broker will flush it's caches so that the garbage collector can
|
||||||
* reclaim more memory.
|
* reclaim more memory.
|
||||||
|
|
Loading…
Reference in New Issue