updates for https://issues.apache.org/activemq/browse/AMQ-894 - provided option to disable statistics gathering

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@506415 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonas B. Lim 2007-02-12 11:20:05 +00:00
parent ef073d1ae9
commit ccf3f3c60d
12 changed files with 151 additions and 29 deletions

View File

@ -103,6 +103,7 @@ public class BrokerService implements Service, Serializable {
public static final String LOCAL_HOST_NAME; public static final String LOCAL_HOST_NAME;
private boolean useJmx = true; private boolean useJmx = true;
private boolean enableStatistics = true;
private boolean persistent = true; private boolean persistent = true;
private boolean populateJMSXUserID = false; private boolean populateJMSXUserID = false;
private boolean useShutdownHook = true; private boolean useShutdownHook = true;
@ -402,6 +403,7 @@ public class BrokerService implements Service, Serializable {
} }
getBroker().start(); getBroker().start();
/* /*
if(isUseJmx()){ if(isUseJmx()){
// yes - this is order dependent! // yes - this is order dependent!
@ -672,6 +674,18 @@ public class BrokerService implements Service, Serializable {
return useJmx; return useJmx;
} }
public boolean isEnableStatistics() {
return enableStatistics;
}
/**
* Sets whether or not the Broker's services enable statistics or
* not.
*/
public void setEnableStatistics(boolean enableStatistics) {
this.enableStatistics = enableStatistics;
}
/** /**
* Sets whether or not the Broker's services should be exposed into JMX or * Sets whether or not the Broker's services should be exposed into JMX or
* not. * not.
@ -1225,6 +1239,11 @@ public class BrokerService implements Service, Serializable {
} }
}; };
RegionBroker rBroker = (RegionBroker) regionBroker;
rBroker.getDestinationStatistics().setEnabled(enableStatistics);
if (isUseJmx()) { if (isUseJmx()) {
ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker; ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
managedBroker.setContextBroker(broker); managedBroker.setContextBroker(broker);
@ -1521,6 +1540,9 @@ public class BrokerService implements Service, Serializable {
if (isUseJmx()) { if (isUseJmx()) {
connector = registerConnectorMBean(connector); connector = registerConnectorMBean(connector);
} }
connector.getStatistics().setEnabled(enableStatistics);
connector.start(); connector.start();
return connector; return connector;

View File

@ -256,6 +256,8 @@ public class TransportConnector implements Connector {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
protected Connection createConnection(Transport transport) throws IOException { protected Connection createConnection(Transport transport) throws IOException {
TransportConnection answer = new TransportConnection(this, transport, broker, disableAsyncDispatch ? null : taskRunnerFactory); TransportConnection answer = new TransportConnection(this, transport, broker, disableAsyncDispatch ? null : taskRunnerFactory);
boolean statEnabled = this.getStatistics().isEnabled();
answer.getStatistics().setEnabled(statEnabled);
answer.setMessageAuthorizationPolicy(messageAuthorizationPolicy); answer.setMessageAuthorizationPolicy(messageAuthorizationPolicy);
return answer; return answer;
} }

View File

@ -92,6 +92,19 @@ public class BrokerView implements BrokerViewMBean {
broker.getDestinationStatistics().reset(); broker.getDestinationStatistics().reset();
} }
public void enableStatistics() {
broker.getDestinationStatistics().setEnabled(true);
}
public void disableStatistics() {
broker.getDestinationStatistics().setEnabled(false);
}
public boolean isStatisticsEnabled() {
return broker.getDestinationStatistics().isEnabled();
}
public void terminateJVM(int exitCode) { public void terminateJVM(int exitCode) {
System.exit(exitCode); System.exit(exitCode);
} }

View File

@ -39,6 +39,10 @@ public interface BrokerViewMBean extends Service {
public void resetStatistics(); public void resetStatistics();
public void enableStatistics();
public void disableStatistics();
public boolean isStatisticsEnabled();
public long getTotalEnqueueCount(); public long getTotalEnqueueCount();
public long getTotalDequeueCount(); public long getTotalDequeueCount();
public long getTotalConsumerCount(); public long getTotalConsumerCount();

View File

@ -55,6 +55,30 @@ public class ConnectorView implements ConnectorViewMBean {
connector.getStatistics().reset(); connector.getStatistics().reset();
} }
/**
* enable statistics gathering
*/
public void enableStatistics() {
connector.getStatistics().setEnabled(true);
}
/**
* disable statistics gathering
*/
public void disableStatistics() {
connector.getStatistics().setEnabled(false);
}
/**
* Returns true if statistics is enabled
*
* @return true if statistics is enabled
*/
public boolean isStatisticsEnabled() {
return connector.getStatistics().isEnabled();
}
/** /**
* Returns the number of messages enqueued on this connector * Returns the number of messages enqueued on this connector
* *

View File

@ -26,6 +26,23 @@ public interface ConnectorViewMBean extends Service {
*/ */
public void resetStatistics(); public void resetStatistics();
/**
* enable statistics gathering
*/
public void enableStatistics();
/**
* disable statistics gathering
*/
public void disableStatistics();
/**
* Returns true if statistics is enabled
*
* @return true if statistics is enabled
*/
public boolean isStatisticsEnabled();
/** /**
* Returns the number of messages enqueued on this connector * Returns the number of messages enqueued on this connector
* *

View File

@ -56,6 +56,12 @@ public class ConnectionStatistics extends StatsImpl {
dequeues.reset(); dequeues.reset();
} }
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
enqueues.setEnabled(enabled);
dequeues.setEnabled(enabled);
}
public void setParent(ConnectorStatistics parent) { public void setParent(ConnectorStatistics parent) {
if (parent != null) { if (parent != null) {
enqueues.setParent(parent.getEnqueues()); enqueues.setParent(parent.getEnqueues());

View File

@ -71,6 +71,15 @@ public class ConnectorStatistics extends StatsImpl {
dequeues.reset(); dequeues.reset();
} }
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
enqueues.setEnabled(enabled);
dequeues.setEnabled(enabled);
consumers.setEnabled(enabled);
messages.setEnabled(enabled);
messagesCached.setEnabled(enabled);
}
public void setParent(ConnectorStatistics parent) { public void setParent(ConnectorStatistics parent) {
if( parent!=null ) { if( parent!=null ) {
enqueues.setParent(parent.enqueues); enqueues.setParent(parent.enqueues);

View File

@ -81,6 +81,17 @@ public class DestinationStatistics extends StatsImpl {
dispatched.reset(); dispatched.reset();
} }
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
enqueues.setEnabled(enabled);
dispatched.setEnabled(enabled);
dequeues.setEnabled(enabled);
consumers.setEnabled(enabled);
messages.setEnabled(enabled);
messagesCached.setEnabled(enabled);
}
public void setParent(DestinationStatistics parent) { public void setParent(DestinationStatistics parent) {
if (parent != null) { if (parent != null) {
enqueues.setParent(parent.enqueues); enqueues.setParent(parent.enqueues);

View File

@ -114,6 +114,8 @@ public class Queue implements Destination, Task {
store.setUsageManager(usageManager); store.setUsageManager(usageManager);
} }
//let's copy the enabled property from the parent DestinationStatistics
this.destinationStatistics.setEnabled(parentStats.isEnabled());
destinationStatistics.setParent(parentStats); destinationStatistics.setParent(parentStats);
this.log = LogFactory.getLog(getClass().getName() + "." + destination.getPhysicalName()); this.log = LogFactory.getLog(getClass().getName() + "." + destination.getPhysicalName());

View File

@ -83,6 +83,8 @@ public class Topic implements Destination {
store.setUsageManager(usageManager); store.setUsageManager(usageManager);
} }
//let's copy the enabled property from the parent DestinationStatistics
this.destinationStatistics.setEnabled(parentStats.isEnabled());
this.destinationStatistics.setParent(parentStats); this.destinationStatistics.setParent(parentStats);
} }

View File

@ -54,40 +54,50 @@ public class CountStatisticImpl extends StatisticImpl implements CountStatistic
} }
public void setCount(long count) { public void setCount(long count) {
if(isEnabled()) {
counter.set(count); counter.set(count);
} }
}
public void add(long amount) { public void add(long amount) {
if (isEnabled()) {
counter.addAndGet(amount); counter.addAndGet(amount);
updateSampleTime(); updateSampleTime();
if (parent != null) { if (parent != null) {
parent.add(amount); parent.add(amount);
} }
} }
}
public void increment() { public void increment() {
if (isEnabled()) {
counter.incrementAndGet(); counter.incrementAndGet();
updateSampleTime(); updateSampleTime();
if (parent != null) { if (parent != null) {
parent.increment(); parent.increment();
} }
} }
}
public void subtract(long amount) { public void subtract(long amount) {
if (isEnabled()) {
counter.addAndGet(-amount); counter.addAndGet(-amount);
updateSampleTime(); updateSampleTime();
if (parent != null) { if (parent != null) {
parent.subtract(amount); parent.subtract(amount);
} }
} }
}
public void decrement() { public void decrement() {
if (isEnabled()) {
counter.decrementAndGet(); counter.decrementAndGet();
updateSampleTime(); updateSampleTime();
if (parent != null) { if (parent != null) {
parent.decrement(); parent.decrement();
} }
} }
}
public CountStatisticImpl getParent() { public CountStatisticImpl getParent() {
return parent; return parent;