1 18 package org.apache.activemq.management; 19 20 import javax.jms.Destination ; 21 import javax.jms.MessageConsumer ; 22 import javax.jms.MessageProducer ; 23 import javax.jms.Session ; 24 25 import org.apache.activemq.util.IndentPrinter; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 35 public class JMSEndpointStatsImpl extends StatsImpl { 36 private static final Log log = LogFactory.getLog(JMSEndpointStatsImpl.class); 37 38 protected CountStatisticImpl messageCount; 39 protected CountStatisticImpl pendingMessageCount; 40 protected CountStatisticImpl expiredMessageCount; 41 protected TimeStatisticImpl messageWaitTime; 42 protected TimeStatisticImpl messageRateTime; 43 44 51 public JMSEndpointStatsImpl(JMSSessionStatsImpl sessionStats) { 52 this(); 53 setParent(messageCount, sessionStats.getMessageCount()); 54 setParent(pendingMessageCount, sessionStats.getPendingMessageCount()); 55 setParent(expiredMessageCount, sessionStats.getExpiredMessageCount()); 56 setParent(messageWaitTime, sessionStats.getMessageWaitTime()); 57 setParent(messageRateTime, sessionStats.getMessageRateTime()); 58 } 59 60 64 public JMSEndpointStatsImpl() { 65 this(new CountStatisticImpl("messageCount", "Number of messages processed"), 66 new CountStatisticImpl("pendingMessageCount", "Number of pending messages"), 67 new CountStatisticImpl("expiredMessageCount", "Number of expired messages"), 68 new TimeStatisticImpl("messageWaitTime", "Time spent by a message before being delivered"), 69 new TimeStatisticImpl("messageRateTime", "Time taken to process a message (thoughtput rate)")); 70 } 71 72 public JMSEndpointStatsImpl(CountStatisticImpl messageCount, CountStatisticImpl pendingMessageCount, CountStatisticImpl expiredMessageCount, TimeStatisticImpl messageWaitTime, TimeStatisticImpl messageRateTime) { 73 this.messageCount = messageCount; 74 this.pendingMessageCount = pendingMessageCount; 75 this.expiredMessageCount = expiredMessageCount; 76 this.messageWaitTime = messageWaitTime; 77 this.messageRateTime = messageRateTime; 78 79 addStatistic("messageCount", messageCount); 81 addStatistic("pendingMessageCount", pendingMessageCount); 82 addStatistic("expiredMessageCount", expiredMessageCount); 83 addStatistic("messageWaitTime", messageWaitTime); 84 addStatistic("messageRateTime", messageRateTime); 85 } 86 87 public synchronized void reset() { 88 super.reset(); 89 messageCount.reset(); 90 messageRateTime.reset(); 91 pendingMessageCount.reset(); 92 expiredMessageCount.reset(); 93 messageWaitTime.reset(); 94 } 95 96 public CountStatisticImpl getMessageCount() { 97 return messageCount; 98 } 99 100 public CountStatisticImpl getPendingMessageCount() { 101 return pendingMessageCount; 102 } 103 104 public CountStatisticImpl getExpiredMessageCount() { 105 return expiredMessageCount; 106 } 107 108 public TimeStatisticImpl getMessageRateTime() { 109 return messageRateTime; 110 } 111 112 public TimeStatisticImpl getMessageWaitTime() { 113 return messageWaitTime; 114 } 115 116 public String toString() { 117 StringBuffer buffer = new StringBuffer (); 118 buffer.append(messageCount); 119 buffer.append(" "); 120 buffer.append(messageRateTime); 121 buffer.append(" "); 122 buffer.append(pendingMessageCount); 123 buffer.append(" "); 124 buffer.append(expiredMessageCount); 125 buffer.append(" "); 126 buffer.append(messageWaitTime); 127 return buffer.toString(); 128 } 129 130 public void onMessage() { 131 if (enabled) { 132 long start = messageCount.getLastSampleTime(); 133 messageCount.increment(); 134 long end = messageCount.getLastSampleTime(); 135 messageRateTime.addTime(end - start); 136 } 137 } 138 139 public void dump(IndentPrinter out) { 140 out.printIndent(); 141 out.println(messageCount); 142 out.printIndent(); 143 out.println(messageRateTime); 144 out.printIndent(); 145 out.println(pendingMessageCount); 146 out.printIndent(); 147 out.println(messageRateTime); 148 out.printIndent(); 149 out.println(expiredMessageCount); 150 out.printIndent(); 151 out.println(messageWaitTime); 152 } 153 154 protected void setParent(CountStatisticImpl child, CountStatisticImpl parent) { 157 if (child instanceof CountStatisticImpl && parent instanceof CountStatisticImpl) { 158 CountStatisticImpl c = (CountStatisticImpl) child; 159 c.setParent((CountStatisticImpl) parent); 160 } 161 else { 162 log.warn("Cannot associate endpoint counters with session level counters as they are not both CountStatisticImpl clases. Endpoint: " + child + " session: " + parent); 163 } 164 } 165 166 protected void setParent(TimeStatisticImpl child, TimeStatisticImpl parent) { 167 if (child instanceof TimeStatisticImpl && parent instanceof TimeStatisticImpl) { 168 TimeStatisticImpl c = (TimeStatisticImpl) child; 169 c.setParent((TimeStatisticImpl) parent); 170 } 171 else { 172 log.warn("Cannot associate endpoint counters with session level counters as they are not both TimeStatisticImpl clases. Endpoint: " + child + " session: " + parent); 173 } 174 } 175 } 176 | Popular Tags |