001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.activemq.broker.region; 019 020import org.apache.activemq.management.CountStatisticImpl; 021import org.apache.activemq.management.SizeStatisticImpl; 022import org.apache.activemq.management.StatsImpl; 023 024/** 025 * The J2EE Statistics for a Subsription. 026 */ 027public class SubscriptionStatistics extends StatsImpl { 028 029 protected CountStatisticImpl consumedCount; 030 protected CountStatisticImpl enqueues; 031 protected CountStatisticImpl dequeues; 032 protected CountStatisticImpl dispatched; 033 protected SizeStatisticImpl inflightMessageSize; 034 035 036 public SubscriptionStatistics() { 037 this(true); 038 } 039 040 public SubscriptionStatistics(boolean enabled) { 041 042 consumedCount = new CountStatisticImpl("consumedCount", "The number of messages that have been consumed by the subscription"); 043 enqueues = new CountStatisticImpl("enqueues", "The number of messages that have been sent to the subscription"); 044 dispatched = new CountStatisticImpl("dispatched", "The number of messages that have been dispatched from the subscription"); 045 dequeues = new CountStatisticImpl("dequeues", "The number of messages that have been acknowledged from the subscription"); 046 inflightMessageSize = new SizeStatisticImpl("inflightMessageSize", "The size in bytes of messages dispatched but awaiting acknowledgement"); 047 048 addStatistic("consumedCount", consumedCount); 049 addStatistic("enqueues", enqueues); 050 addStatistic("dispatched", dispatched); 051 addStatistic("dequeues", dequeues); 052 addStatistic("inflightMessageSize", inflightMessageSize); 053 054 this.setEnabled(enabled); 055 } 056 057 public CountStatisticImpl getConsumedCount() { 058 return consumedCount; 059 } 060 061 public CountStatisticImpl getEnqueues() { 062 return enqueues; 063 } 064 065 public CountStatisticImpl getDequeues() { 066 return dequeues; 067 } 068 069 public CountStatisticImpl getDispatched() { 070 return dispatched; 071 } 072 073 public SizeStatisticImpl getInflightMessageSize() { 074 return inflightMessageSize; 075 } 076 077 public void reset() { 078 if (this.isDoReset()) { 079 super.reset(); 080 consumedCount.reset(); 081 enqueues.reset(); 082 dequeues.reset(); 083 dispatched.reset(); 084 inflightMessageSize.reset(); 085 } 086 } 087 088 public void setEnabled(boolean enabled) { 089 super.setEnabled(enabled); 090 consumedCount.setEnabled(enabled); 091 enqueues.setEnabled(enabled); 092 dispatched.setEnabled(enabled); 093 dequeues.setEnabled(enabled); 094 inflightMessageSize.setEnabled(enabled); 095 } 096 097 public void setParent(SubscriptionStatistics parent) { 098 if (parent != null) { 099 consumedCount.setParent(parent.consumedCount); 100 enqueues.setParent(parent.enqueues); 101 dispatched.setParent(parent.dispatched); 102 dequeues.setParent(parent.dequeues); 103 inflightMessageSize.setParent(parent.inflightMessageSize); 104 } else { 105 consumedCount.setParent(null); 106 enqueues.setParent(null); 107 dispatched.setParent(null); 108 dequeues.setParent(null); 109 inflightMessageSize.setParent(null); 110 } 111 } 112 113}