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.PollCountStatisticImpl;
022import org.apache.activemq.management.StatsImpl;
023import org.apache.activemq.management.TimeStatisticImpl;
024
025/**
026 * The J2EE Statistics for the a Destination.
027 *
028 *
029 */
030public 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
043    public DestinationStatistics() {
044
045        enqueues = new CountStatisticImpl("enqueues", "The number of messages that have been sent to the destination");
046        dispatched = new CountStatisticImpl("dispatched", "The number of messages that have been dispatched from the destination");
047        dequeues = new CountStatisticImpl("dequeues", "The number of messages that have been acknowledged from the destination");
048        inflight = new CountStatisticImpl("inflight", "The number of messages dispatched but awaiting acknowledgement");
049        expired = new CountStatisticImpl("expired", "The number of messages that have expired");
050
051        consumers = new CountStatisticImpl("consumers", "The number of consumers that that are subscribing to messages from the destination");
052        consumers.setDoReset(false);
053        producers = new CountStatisticImpl("producers", "The number of producers that that are publishing messages to the destination");
054        producers.setDoReset(false);
055        messages = new CountStatisticImpl("messages", "The number of messages that that are being held by the destination");
056        messages.setDoReset(false);
057        messagesCached = new PollCountStatisticImpl("messagesCached", "The number of messages that are held in the destination's memory cache");
058        processTime = new TimeStatisticImpl("processTime", "information around length of time messages are held by a destination");
059        addStatistic("enqueues", enqueues);
060        addStatistic("dispatched", dispatched);
061        addStatistic("dequeues", dequeues);
062        addStatistic("inflight", inflight);
063        addStatistic("expired", expired);
064        addStatistic("consumers", consumers);
065        addStatistic("producers", producers);
066        addStatistic("messages", messages);
067        addStatistic("messagesCached", messagesCached);
068        addStatistic("processTime", processTime);
069    }
070
071    public CountStatisticImpl getEnqueues() {
072        return enqueues;
073    }
074
075    public CountStatisticImpl getDequeues() {
076        return dequeues;
077    }
078
079    public CountStatisticImpl getInflight() {
080        return inflight;
081    }
082
083    public CountStatisticImpl getExpired() {
084        return expired;
085    }
086
087    public CountStatisticImpl getConsumers() {
088        return consumers;
089    }
090
091    public CountStatisticImpl getProducers() {
092        return producers;
093    }
094
095    public PollCountStatisticImpl getMessagesCached() {
096        return messagesCached;
097    }
098
099    public CountStatisticImpl getMessages() {
100        return messages;
101    }
102
103    public void setMessagesCached(PollCountStatisticImpl messagesCached) {
104        this.messagesCached = messagesCached;
105    }
106
107    public CountStatisticImpl getDispatched() {
108        return dispatched;
109    }
110
111    public TimeStatisticImpl getProcessTime() {
112        return this.processTime;
113    }
114
115    public void reset() {
116        if (this.isDoReset()) {
117            super.reset();
118            enqueues.reset();
119            dequeues.reset();
120            dispatched.reset();
121            inflight.reset();
122            expired.reset();
123        }
124    }
125
126    public void setEnabled(boolean enabled) {
127        super.setEnabled(enabled);
128        enqueues.setEnabled(enabled);
129        dispatched.setEnabled(enabled);
130        dequeues.setEnabled(enabled);
131        inflight.setEnabled(enabled);
132        expired.setEnabled(true);
133        consumers.setEnabled(enabled);
134        producers.setEnabled(enabled);
135        messages.setEnabled(enabled);
136        messagesCached.setEnabled(enabled);
137        processTime.setEnabled(enabled);
138
139    }
140
141    public void setParent(DestinationStatistics parent) {
142        if (parent != null) {
143            enqueues.setParent(parent.enqueues);
144            dispatched.setParent(parent.dispatched);
145            dequeues.setParent(parent.dequeues);
146            inflight.setParent(parent.inflight);
147            expired.setParent(parent.expired);
148            consumers.setParent(parent.consumers);
149            producers.setParent(parent.producers);
150            messagesCached.setParent(parent.messagesCached);
151            messages.setParent(parent.messages);
152            processTime.setParent(parent.processTime);
153        } else {
154            enqueues.setParent(null);
155            dispatched.setParent(null);
156            dequeues.setParent(null);
157            inflight.setParent(null);
158            expired.setParent(null);
159            consumers.setParent(null);
160            producers.setParent(null);
161            messagesCached.setParent(null);
162            messages.setParent(null);
163            processTime.setParent(null);
164        }
165    }
166
167}