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.network;
019
020import org.apache.activemq.management.CountStatisticImpl;
021import org.apache.activemq.management.StatsImpl;
022
023/**
024 * The Statistics for a NetworkBridge.
025 */
026public class NetworkBridgeStatistics extends StatsImpl {
027
028    protected CountStatisticImpl enqueues;
029    protected CountStatisticImpl dequeues;
030    protected CountStatisticImpl receivedCount;
031
032    public NetworkBridgeStatistics() {
033        enqueues = new CountStatisticImpl("enqueues", "The current number of enqueues this bridge has, which is the number of potential messages to be forwarded.");
034        dequeues = new CountStatisticImpl("dequeues", "The current number of dequeues this bridge has, which is the number of messages received by the remote broker.");
035        receivedCount = new CountStatisticImpl("receivedCount", "The number of messages that have been received by the NetworkBridge from the remote broker.  Only applies for Duplex bridges.");
036
037        addStatistic("enqueues", enqueues);
038        addStatistic("dequeues", dequeues);
039        addStatistic("receivedCount", receivedCount);
040    }
041
042    /**
043     * The current number of enqueues this bridge has, which is the number of potential messages to be forwarded
044     * Messages may not be forwarded if there is no subscription
045     *
046     * @return
047     */
048    public CountStatisticImpl getEnqueues() {
049        return enqueues;
050    }
051
052    /**
053     * The current number of dequeues this bridge has, which is the number of
054     * messages actually sent to and received by the remote broker.
055     *
056     * @return
057     */
058    public CountStatisticImpl getDequeues() {
059        return dequeues;
060    }
061
062    /**
063     * The number of messages that have been received by the NetworkBridge from the remote broker.
064     * Only applies for Duplex bridges.
065     *
066     * @return
067     */
068    public CountStatisticImpl getReceivedCount() {
069        return receivedCount;
070    }
071
072    @Override
073    public void reset() {
074        if (this.isDoReset()) {
075            super.reset();
076            enqueues.reset();
077            dequeues.reset();
078            receivedCount.reset();
079        }
080    }
081
082    @Override
083    public void setEnabled(boolean enabled) {
084        super.setEnabled(enabled);
085        enqueues.setEnabled(enabled);
086        dequeues.setEnabled(enabled);
087        receivedCount.setEnabled(enabled);
088    }
089
090    public void setParent(NetworkBridgeStatistics parent) {
091        if (parent != null) {
092            enqueues.setParent(parent.enqueues);
093            dequeues.setParent(parent.dequeues);
094            receivedCount.setParent(parent.receivedCount);
095        } else {
096            enqueues.setParent(null);
097            dequeues.setParent(null);
098            receivedCount.setParent(null);
099        }
100    }
101
102}