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.store;
019
020import org.apache.activemq.management.CountStatisticImpl;
021import org.apache.activemq.management.SizeStatisticImpl;
022import org.apache.activemq.management.StatsImpl;
023
024
025public abstract class AbstractMessageStoreStatistics extends StatsImpl {
026
027    protected final CountStatisticImpl messageCount;
028    protected final SizeStatisticImpl messageSize;
029
030
031    protected AbstractMessageStoreStatistics(String countDescription, String sizeDescription) {
032        this(true, countDescription, sizeDescription);
033    }
034
035    protected AbstractMessageStoreStatistics(boolean enabled, String countDescription, String sizeDescription) {
036
037        messageCount = new CountStatisticImpl("messageCount", countDescription);
038        messageSize = new SizeStatisticImpl("messageSize", sizeDescription);
039
040        addStatistic("messageCount", messageCount);
041        addStatistic("messageSize", messageSize);
042
043        this.setEnabled(enabled);
044    }
045
046
047    public CountStatisticImpl getMessageCount() {
048        return messageCount;
049    }
050
051    public SizeStatisticImpl getMessageSize() {
052        return messageSize;
053    }
054
055    @Override
056    public void reset() {
057        if (this.isDoReset()) {
058            super.reset();
059            messageCount.reset();
060            messageSize.reset();
061        }
062    }
063
064    @Override
065    public void setEnabled(boolean enabled) {
066        super.setEnabled(enabled);
067        messageCount.setEnabled(enabled);
068        messageSize.setEnabled(enabled);
069    }
070
071    public void setParent(AbstractMessageStoreStatistics parent) {
072        if (parent != null) {
073            messageCount.setParent(parent.messageCount);
074            messageSize.setParent(parent.messageSize);
075        } else {
076            messageCount.setParent(null);
077            messageSize.setParent(null);
078        }
079    }
080
081}