activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r520870 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker: BrokerRegistry.java BrokerService.java
Date Wed, 21 Mar 2007 12:54:11 GMT
Author: rajdavies
Date: Wed Mar 21 05:54:10 2007
New Revision: 520870

URL: http://svn.apache.org/viewvc?view=rev&rev=520870
Log:
If localhost broker not started and other named broker exists - use that from vm:// transport
instead of creating a new broker 

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java?view=diff&rev=520870&r1=520869&r2=520870
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerRegistry.java
Wed Mar 21 05:54:10 2007
@@ -1,73 +1,94 @@
 /**
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements. See the NOTICE
+ * file distributed with this work for additional information regarding copyright ownership.
The ASF licenses this file
+ * to You under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance with the
+ * License. You may obtain a copy of the License at
+ * 
  * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the
+ * specific language governing permissions and limitations under the License.
  */
+
 package org.apache.activemq.broker;
 
 import java.util.HashMap;
 import java.util.Iterator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * 
  * @version $Revision: 1.3 $
  */
-public class BrokerRegistry {
+public class BrokerRegistry{
 
-    static final private BrokerRegistry instance = new BrokerRegistry();
-    
-    public static BrokerRegistry getInstance() {
+    private static final Log log=LogFactory.getLog(BrokerRegistry.class);
+    static final private BrokerRegistry instance=new BrokerRegistry();
+
+    public static BrokerRegistry getInstance(){
         return instance;
     }
+    private final Object mutex=new Object();
+    private final HashMap<String,BrokerService> brokers=new HashMap<String,BrokerService>();
 
-    private final Object mutex = new Object();
-    private final HashMap brokers = new HashMap();
-    
-    public BrokerService lookup(String brokerName) {
-        synchronized(mutex) {
-            return (BrokerService)brokers.get(brokerName);
+    /**
+     * @param brokerName
+     * @return the BrokerService
+     */
+    public BrokerService lookup(String brokerName){
+        BrokerService result=null;
+        synchronized(mutex){
+            result=brokers.get(brokerName);
+            if(result==null&&brokerName!=null&&brokerName.equals(BrokerService.DEFAULT_BROKER_NAME)){
+                result=findFirst();
+                if(result!=null){
+                    log.warn("Broker localhost not started so using "+result.getBrokerName()+"
instead");
+                }
+            }
         }
+        return result;
     }
 
     /**
      * Returns the first registered broker found
+     * @return the first BrokerService
      */
-    public BrokerService findFirst() {
-        synchronized(mutex) {
-            Iterator iter = brokers.values().iterator();
-            while (iter.hasNext()) {
-            return (BrokerService) iter.next();
+    public BrokerService findFirst(){
+        synchronized(mutex){
+            Iterator<BrokerService> iter=brokers.values().iterator();
+            while(iter.hasNext()){
+                return iter.next();
             }
             return null;
         }
     }
 
-    public void bind(String brokerName, BrokerService broker) {
-        synchronized(mutex) {
-            brokers.put(brokerName, broker);
+    /**
+     * @param brokerName
+     * @param broker
+     */
+    public void bind(String brokerName,BrokerService broker){
+        synchronized(mutex){
+            brokers.put(brokerName,broker);
         }
     }
-    
-    public void unbind(String brokerName) {
-        synchronized(mutex) {
+
+    /**
+     * @param brokerName
+     */
+    public void unbind(String brokerName){
+        synchronized(mutex){
             brokers.remove(brokerName);
         }
     }
 
-    public Object getRegistryMutext() {
+    /**
+     * @return the mutex used
+     */
+    public Object getRegistryMutext(){
         return mutex;
     }
-
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?view=diff&rev=520870&r1=520869&r2=520870
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Wed Mar 21 05:54:10 2007
@@ -100,7 +100,7 @@
     private static final Log log = LogFactory.getLog(BrokerService.class);
     private static final long serialVersionUID = 7353129142305630237L;
     public static final String DEFAULT_PORT = "61616";
-    public static final String DEFAULT_BROKER_NAME = "localhost";
+    static final String DEFAULT_BROKER_NAME = "localhost";
     public static final String LOCAL_HOST_NAME;
 
     private boolean useJmx = true;



Mime
View raw message