mirror of https://github.com/apache/activemq.git
If localhost broker not started and other named broker exists - use that from vm:// transport instead of creating a new broker
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@520870 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c328c72472
commit
a2aed3d732
|
@ -1,24 +1,23 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
|
||||||
* this work for additional information regarding copyright ownership.
|
* to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
* License. You may obtain a copy of the License at
|
||||||
* (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
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* specific language governing permissions and limitations under the License.
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.activemq.broker;
|
package org.apache.activemq.broker;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -26,48 +25,70 @@ import java.util.Iterator;
|
||||||
*/
|
*/
|
||||||
public class BrokerRegistry{
|
public class BrokerRegistry{
|
||||||
|
|
||||||
|
private static final Log log=LogFactory.getLog(BrokerRegistry.class);
|
||||||
static final private BrokerRegistry instance=new BrokerRegistry();
|
static final private BrokerRegistry instance=new BrokerRegistry();
|
||||||
|
|
||||||
public static BrokerRegistry getInstance(){
|
public static BrokerRegistry getInstance(){
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Object mutex=new Object();
|
private final Object mutex=new Object();
|
||||||
private final HashMap brokers = new HashMap();
|
private final HashMap<String,BrokerService> brokers=new HashMap<String,BrokerService>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param brokerName
|
||||||
|
* @return the BrokerService
|
||||||
|
*/
|
||||||
public BrokerService lookup(String brokerName){
|
public BrokerService lookup(String brokerName){
|
||||||
|
BrokerService result=null;
|
||||||
synchronized(mutex){
|
synchronized(mutex){
|
||||||
return (BrokerService)brokers.get(brokerName);
|
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
|
* Returns the first registered broker found
|
||||||
|
* @return the first BrokerService
|
||||||
*/
|
*/
|
||||||
public BrokerService findFirst(){
|
public BrokerService findFirst(){
|
||||||
synchronized(mutex){
|
synchronized(mutex){
|
||||||
Iterator iter = brokers.values().iterator();
|
Iterator<BrokerService> iter=brokers.values().iterator();
|
||||||
while(iter.hasNext()){
|
while(iter.hasNext()){
|
||||||
return (BrokerService) iter.next();
|
return iter.next();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param brokerName
|
||||||
|
* @param broker
|
||||||
|
*/
|
||||||
public void bind(String brokerName,BrokerService broker){
|
public void bind(String brokerName,BrokerService broker){
|
||||||
synchronized(mutex){
|
synchronized(mutex){
|
||||||
brokers.put(brokerName,broker);
|
brokers.put(brokerName,broker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param brokerName
|
||||||
|
*/
|
||||||
public void unbind(String brokerName){
|
public void unbind(String brokerName){
|
||||||
synchronized(mutex){
|
synchronized(mutex){
|
||||||
brokers.remove(brokerName);
|
brokers.remove(brokerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the mutex used
|
||||||
|
*/
|
||||||
public Object getRegistryMutext(){
|
public Object getRegistryMutext(){
|
||||||
return mutex;
|
return mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class BrokerService implements Service, Serializable {
|
||||||
private static final Log log = LogFactory.getLog(BrokerService.class);
|
private static final Log log = LogFactory.getLog(BrokerService.class);
|
||||||
private static final long serialVersionUID = 7353129142305630237L;
|
private static final long serialVersionUID = 7353129142305630237L;
|
||||||
public static final String DEFAULT_PORT = "61616";
|
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;
|
public static final String LOCAL_HOST_NAME;
|
||||||
|
|
||||||
private boolean useJmx = true;
|
private boolean useJmx = true;
|
||||||
|
|
Loading…
Reference in New Issue