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

@ -864,6 +864,21 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
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

@ -55,6 +55,18 @@ public class JMSConnectionStatsImpl extends StatsImpl {
}
}
/**
* @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() {
return transactional;

View File

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

View File

@ -96,6 +96,22 @@ public class JMSSessionStatsImpl extends StatsImpl {
}
}
/**
* @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;
@ -76,6 +77,20 @@ public class StatisticImpl implements Statistic, Resettable {
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: ");
buffer.append(unit);
@ -88,4 +103,7 @@ public class StatisticImpl implements Statistic, Resettable {
buffer.append(" description: ");
buffer.append(description);
}
}