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    package org.apache.activemq.broker.view;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.apache.activemq.broker.BrokerRegistry;
023    import org.apache.activemq.broker.BrokerService;
024    
025    public class MessageBrokerViewRegistry {
026    
027        private static final MessageBrokerViewRegistry INSTANCE = new MessageBrokerViewRegistry();
028    
029        private final Object mutex = new Object();
030        private final Map<String, MessageBrokerView> brokerViews = new HashMap<String, MessageBrokerView>();
031    
032        public static MessageBrokerViewRegistry getInstance() {
033            return INSTANCE;
034        }
035    
036        /**
037         * @param brokerName
038         * @return the BrokerService
039         */
040        public MessageBrokerView lookup(String brokerName) {
041            MessageBrokerView result = null;
042            synchronized (mutex) {
043                result = brokerViews.get(brokerName);
044                if (result==null){
045                    BrokerService brokerService = BrokerRegistry.getInstance().lookup(brokerName);
046                    if (brokerService != null){
047                        result = new MessageBrokerView(brokerService);
048                        brokerViews.put(brokerName,result);
049                    }
050                }
051    
052            }
053            return result;
054        }
055    }