make enabling statistics configurable

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@470387 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-11-02 15:33:25 +00:00
parent 12fff78943
commit 526cb5bae8
7 changed files with 96 additions and 5 deletions

View File

@ -863,6 +863,21 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
public void setSessionTaskRunner(TaskRunnerFactory sessionTaskRunner) {
this.sessionTaskRunner = sessionTaskRunner;
}
/**
* @return the statsEnabled
*/
public boolean isStatsEnabled(){
return this.stats.isEnabled();
}
/**
* @param statsEnabled the statsEnabled to set
*/
public void setStatsEnabled(boolean statsEnabled){
this.stats.setEnabled(statsEnabled);
}
// Implementation methods

View File

@ -85,7 +85,6 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
private int closeTimeout = 15000;
private boolean useRetroactiveConsumer;
private boolean nestedMapAndListEnabled = true;
JMSStatsImpl factoryStats = new JMSStatsImpl();
static protected final Executor DEFAULT_CONNECTION_EXECUTOR = new ScheduledThreadPoolExecutor(5, new ThreadFactory() {
@ -519,6 +518,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
props.setProperty("closeTimeout", Integer.toString(getCloseTimeout()));
props.setProperty("alwaysSessionAsync", Boolean.toString(isAlwaysSessionAsync()));
props.setProperty("optimizeAcknowledge", Boolean.toString(isOptimizeAcknowledge()));
props.setProperty("statsEnabled",Boolean.toString(isStatsEnabled()));
}
@ -662,4 +662,20 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
protected void setClientIdGenerator(IdGenerator clientIdGenerator) {
this.clientIdGenerator = clientIdGenerator;
}
/**
* @return the statsEnabled
*/
public boolean isStatsEnabled(){
return this.factoryStats.isEnabled();
}
/**
* @param statsEnabled the statsEnabled to set
*/
public void setStatsEnabled(boolean statsEnabled){
this.factoryStats.setEnabled(statsEnabled);
}
}

View File

@ -54,6 +54,18 @@ public class JMSConnectionStatsImpl extends StatsImpl {
stats[i].reset();
}
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled){
super.setEnabled(enabled);
JMSSessionStatsImpl[] stats = getSessions();
for (int i = 0, size = stats.length; i < size; i++) {
stats[i].setEnabled(enabled);
}
}
public boolean isTransactional() {

View File

@ -128,10 +128,12 @@ public class JMSEndpointStatsImpl extends StatsImpl {
}
public void onMessage() {
long start = messageCount.getLastSampleTime();
messageCount.increment();
long end = messageCount.getLastSampleTime();
messageRateTime.addTime(end - start);
if (enabled) {
long start = messageCount.getLastSampleTime();
messageCount.increment();
long end = messageCount.getLastSampleTime();
messageRateTime.addTime(end - start);
}
}
public void dump(IndentPrinter out) {

View File

@ -95,6 +95,22 @@ public class JMSSessionStatsImpl extends StatsImpl {
pstats[i].reset();
}
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled){
super.setEnabled(enabled);
JMSConsumerStatsImpl[] cstats = getConsumers();
for (int i = 0, size = cstats.length; i < size; i++) {
cstats[i].setEnabled(enabled);
}
JMSProducerStatsImpl[] pstats = getProducers();
for (int i = 0, size = pstats.length; i < size; i++) {
pstats[i].setEnabled(enabled);
}
}
public CountStatisticImpl getMessageCount() {
return messageCount;

View File

@ -68,4 +68,16 @@ public class JMSStatsImpl extends StatsImpl {
out.println("}");
out.flush();
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled){
super.setEnabled(enabled);
JMSConnectionStatsImpl[] stats = getConnections();
for (int i = 0, size = stats.length; i < size; i++) {
stats[i].setEnabled(enabled);
}
}
}

View File

@ -29,6 +29,7 @@ public class StatisticImpl implements Statistic, Resettable {
private String description;
private long startTime;
private long lastSampleTime;
protected boolean enabled= true;
public StatisticImpl(String name, String unit, String description) {
this.name = name;
@ -75,6 +76,20 @@ public class StatisticImpl implements Statistic, Resettable {
public synchronized long getLastSampleTime() {
return lastSampleTime;
}
/**
* @return the enabled
*/
public boolean isEnabled(){
return this.enabled;
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled){
this.enabled=enabled;
}
protected synchronized void appendFieldDescription(StringBuffer buffer) {
buffer.append(" unit: ");
@ -88,4 +103,7 @@ public class StatisticImpl implements Statistic, Resettable {
buffer.append(" description: ");
buffer.append(description);
}
}