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 */
017package org.apache.activemq.broker.jmx;
018
019import java.util.List;
020import java.util.concurrent.CopyOnWriteArrayList;
021
022import org.apache.activemq.network.NetworkBridge;
023
024public class NetworkBridgeView implements NetworkBridgeViewMBean {
025
026    private final NetworkBridge bridge;
027    private boolean createByDuplex = false;
028    private List<NetworkDestinationView> networkDestinationViewList = new CopyOnWriteArrayList<NetworkDestinationView>();
029
030    public NetworkBridgeView(NetworkBridge bridge) {
031        this.bridge = bridge;
032    }
033
034    @Override
035    public void start() throws Exception {
036        bridge.start();
037    }
038
039    @Override
040    public void stop() throws Exception {
041        bridge.stop();
042    }
043
044    @Override
045    public String getLocalAddress() {
046        return bridge.getLocalAddress();
047    }
048
049    @Override
050    public String getRemoteAddress() {
051        return bridge.getRemoteAddress();
052    }
053
054    @Override
055    public String getRemoteBrokerName() {
056        return bridge.getRemoteBrokerName();
057    }
058
059
060    @Override
061    public String getRemoteBrokerId() {
062        return bridge.getRemoteBrokerId();
063    }
064
065    @Override
066    public String getLocalBrokerName() {
067        return bridge.getLocalBrokerName();
068    }
069
070    @Override
071    public long getEnqueueCounter() {
072        return bridge.getEnqueueCounter();
073    }
074
075    @Override
076    public long getDequeueCounter() {
077        return bridge.getDequeueCounter();
078    }
079
080    @Override
081    public long getReceivedCounter() {
082        return bridge.getNetworkBridgeStatistics().getReceivedCount().getCount();
083    }
084
085    @Override
086    public boolean isCreatedByDuplex() {
087        return createByDuplex;
088    }
089
090    public void setCreateByDuplex(boolean createByDuplex) {
091        this.createByDuplex = createByDuplex;
092    }
093
094    @Override
095    public void resetStats(){
096        bridge.resetStats();
097        for (NetworkDestinationView networkDestinationView:networkDestinationViewList){
098            networkDestinationView.resetStats();
099        }
100    }
101
102    public void addNetworkDestinationView(NetworkDestinationView networkDestinationView){
103        networkDestinationViewList.add(networkDestinationView);
104    }
105
106    public void removeNetworkDestinationView(NetworkDestinationView networkDestinationView){
107        networkDestinationViewList.remove(networkDestinationView);
108    }
109}