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    
018    package org.apache.activemq.broker.region;
019    
020    import org.apache.activemq.management.CountStatisticImpl;
021    import org.apache.activemq.management.PollCountStatisticImpl;
022    import org.apache.activemq.management.StatsImpl;
023    import org.apache.activemq.management.*;
024    
025    /**
026     * The J2EE Statistics for the a Destination.
027     *
028     *
029     */
030    public class DestinationStatistics extends StatsImpl {
031    
032        protected CountStatisticImpl enqueues;
033        protected CountStatisticImpl dequeues;
034        protected CountStatisticImpl consumers;
035        protected CountStatisticImpl producers;
036        protected CountStatisticImpl messages;
037        protected PollCountStatisticImpl messagesCached;
038        protected CountStatisticImpl dispatched;
039        protected CountStatisticImpl inflight;
040        protected CountStatisticImpl expired;
041        protected TimeStatisticImpl processTime;
042        protected CountStatisticImpl blockedSends;
043        protected TimeStatisticImpl blockedTime;
044        protected SizeStatisticImpl messageSize;
045    
046    
047        public DestinationStatistics() {
048    
049            enqueues = new CountStatisticImpl("enqueues", "The number of messages that have been sent to the destination");
050            dispatched = new CountStatisticImpl("dispatched", "The number of messages that have been dispatched from the destination");
051            dequeues = new CountStatisticImpl("dequeues", "The number of messages that have been acknowledged from the destination");
052            inflight = new CountStatisticImpl("inflight", "The number of messages dispatched but awaiting acknowledgement");
053            expired = new CountStatisticImpl("expired", "The number of messages that have expired");
054    
055            consumers = new CountStatisticImpl("consumers", "The number of consumers that that are subscribing to messages from the destination");
056            consumers.setDoReset(false);
057            producers = new CountStatisticImpl("producers", "The number of producers that that are publishing messages to the destination");
058            producers.setDoReset(false);
059            messages = new CountStatisticImpl("messages", "The number of messages that that are being held by the destination");
060            messages.setDoReset(false);
061            messagesCached = new PollCountStatisticImpl("messagesCached", "The number of messages that are held in the destination's memory cache");
062            processTime = new TimeStatisticImpl("processTime", "information around length of time messages are held by a destination");
063            blockedSends = new CountStatisticImpl("blockedSends", "number of messages that have to wait for flow control");
064            blockedTime = new TimeStatisticImpl("blockedTime","amount of time messages are blocked for flow control");
065            messageSize = new SizeStatisticImpl("messageSize","Size of messages passing through the destination");
066            addStatistic("enqueues", enqueues);
067            addStatistic("dispatched", dispatched);
068            addStatistic("dequeues", dequeues);
069            addStatistic("inflight", inflight);
070            addStatistic("expired", expired);
071            addStatistic("consumers", consumers);
072            addStatistic("producers", producers);
073            addStatistic("messages", messages);
074            addStatistic("messagesCached", messagesCached);
075            addStatistic("processTime", processTime);
076            addStatistic("blockedSends",blockedSends);
077            addStatistic("blockedTime",blockedTime);
078            addStatistic("messageSize",messageSize);
079        }
080    
081        public CountStatisticImpl getEnqueues() {
082            return enqueues;
083        }
084    
085        public CountStatisticImpl getDequeues() {
086            return dequeues;
087        }
088    
089        public CountStatisticImpl getInflight() {
090            return inflight;
091        }
092    
093        public CountStatisticImpl getExpired() {
094            return expired;
095        }
096    
097        public CountStatisticImpl getConsumers() {
098            return consumers;
099        }
100    
101        public CountStatisticImpl getProducers() {
102            return producers;
103        }
104    
105        public PollCountStatisticImpl getMessagesCached() {
106            return messagesCached;
107        }
108    
109        public CountStatisticImpl getMessages() {
110            return messages;
111        }
112    
113        public void setMessagesCached(PollCountStatisticImpl messagesCached) {
114            this.messagesCached = messagesCached;
115        }
116    
117        public CountStatisticImpl getDispatched() {
118            return dispatched;
119        }
120    
121        public TimeStatisticImpl getProcessTime() {
122            return this.processTime;
123        }
124    
125        public CountStatisticImpl getBlockedSends(){
126            return this.blockedSends;
127        }
128        public TimeStatisticImpl getBlockedTime(){
129            return this.blockedTime;
130        }
131        public SizeStatisticImpl getMessageSize(){
132            return this.messageSize;
133        }
134    
135        public void reset() {
136            if (this.isDoReset()) {
137                super.reset();
138                enqueues.reset();
139                dequeues.reset();
140                dispatched.reset();
141                inflight.reset();
142                expired.reset();
143                blockedSends.reset();
144                blockedTime.reset();
145                messageSize.reset();
146            }
147        }
148    
149        public void setEnabled(boolean enabled) {
150            super.setEnabled(enabled);
151            enqueues.setEnabled(enabled);
152            dispatched.setEnabled(enabled);
153            dequeues.setEnabled(enabled);
154            inflight.setEnabled(enabled);
155            expired.setEnabled(true);
156            consumers.setEnabled(enabled);
157            producers.setEnabled(enabled);
158            messages.setEnabled(enabled);
159            messagesCached.setEnabled(enabled);
160            processTime.setEnabled(enabled);
161            blockedSends.setEnabled(enabled);
162            blockedTime.setEnabled(enabled);
163            messageSize.setEnabled(enabled);
164    
165        }
166    
167        public void setParent(DestinationStatistics parent) {
168            if (parent != null) {
169                enqueues.setParent(parent.enqueues);
170                dispatched.setParent(parent.dispatched);
171                dequeues.setParent(parent.dequeues);
172                inflight.setParent(parent.inflight);
173                expired.setParent(parent.expired);
174                consumers.setParent(parent.consumers);
175                producers.setParent(parent.producers);
176                messagesCached.setParent(parent.messagesCached);
177                messages.setParent(parent.messages);
178                processTime.setParent(parent.processTime);
179                blockedSends.setParent(parent.blockedSends);
180                blockedTime.setParent(parent.blockedTime);
181                messageSize.setParent(parent.messageSize);
182            } else {
183                enqueues.setParent(null);
184                dispatched.setParent(null);
185                dequeues.setParent(null);
186                inflight.setParent(null);
187                expired.setParent(null);
188                consumers.setParent(null);
189                producers.setParent(null);
190                messagesCached.setParent(null);
191                messages.setParent(null);
192                processTime.setParent(null);
193                blockedSends.setParent(null);
194                blockedTime.setParent(null);
195                messageSize.setParent(null);
196            }
197        }
198    
199    }