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;
private boolean useJmx = true;
private boolean enableStatistics = true;
private boolean persistent = true;
private boolean populateJMSXUserID = false;
private boolean useShutdownHook = true;
@ -402,6 +403,7 @@ public class BrokerService implements Service, Serializable {
}
getBroker().start();
/*
if(isUseJmx()){
// yes - this is order dependent!
@ -671,7 +673,19 @@ public class BrokerService implements Service, Serializable {
public boolean isUseJmx() {
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
* not.
@ -1224,6 +1238,11 @@ public class BrokerService implements Service, Serializable {
});
}
};
RegionBroker rBroker = (RegionBroker) regionBroker;
rBroker.getDestinationStatistics().setEnabled(enableStatistics);
if (isUseJmx()) {
ManagedRegionBroker managedBroker = (ManagedRegionBroker) regionBroker;
@ -1521,6 +1540,9 @@ public class BrokerService implements Service, Serializable {
if (isUseJmx()) {
connector = registerConnectorMBean(connector);
}
connector.getStatistics().setEnabled(enableStatistics);
connector.start();
return connector;

View File

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

View File

@ -91,6 +91,19 @@ public class BrokerView implements BrokerViewMBean {
public void resetStatistics() {
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) {
System.exit(exitCode);

View File

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

View File

@ -54,6 +54,30 @@ public class ConnectorView implements ConnectorViewMBean {
public void resetStatistics() {
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

View File

@ -25,6 +25,23 @@ public interface ConnectorViewMBean extends Service {
* Resets the statistics
*/
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

View File

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

View File

@ -71,6 +71,15 @@ public class ConnectorStatistics extends StatsImpl {
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) {
if( parent!=null ) {
enqueues.setParent(parent.enqueues);

View File

@ -79,7 +79,18 @@ public class DestinationStatistics extends StatsImpl {
enqueues.reset();
dequeues.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) {
if (parent != null) {

View File

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

View File

@ -82,7 +82,9 @@ public class Topic implements Destination {
if( store!=null ) {
store.setUsageManager(usageManager);
}
//let's copy the enabled property from the parent DestinationStatistics
this.destinationStatistics.setEnabled(parentStats.isEnabled());
this.destinationStatistics.setParent(parentStats);
}

View File

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