Handle duplicate destinations & concurrency issues better

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@509706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2007-02-20 18:59:02 +00:00
parent bca88fee18
commit b006e61e4f
3 changed files with 51 additions and 3 deletions

View File

@ -0,0 +1,40 @@
/**
*
* 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.
*/
package org.apache.activemq.broker;
import org.apache.activemq.command.ActiveMQDestination;
import javax.jms.JMSException;
/**
* An exception thrown if a destination is attempted to be created when it already exists.
*
* @version $Revision$
*/
public class DestinationAlreadyExistsException extends JMSException {
private final ActiveMQDestination destination;
public DestinationAlreadyExistsException(ActiveMQDestination destination) {
super("Destination already exists: " + destination);
this.destination = destination;
}
public ActiveMQDestination getDestination() {
return destination;
}
}

View File

@ -25,6 +25,7 @@ import java.util.Set;
import javax.jms.JMSException;
import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.DestinationAlreadyExistsException;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ConsumerInfo;
import org.apache.activemq.command.Message;
@ -326,9 +327,15 @@ abstract public class AbstractRegion implements Region {
if(autoCreateDestinations){
// Try to auto create the destination... re-invoke broker from the
// top so that the proper security checks are performed.
context.getBroker().addDestination(context,destination);
try {
dest = addDestination(context, destination);
//context.getBroker().addDestination(context,destination);
}
catch (DestinationAlreadyExistsException e) {
// if the destination already exists then lets ignore this error
}
// We should now have the dest created.
dest=(Destination) destinations.get(destination);
//dest=(Destination) destinations.get(destination);
}
if(dest==null){
throw new JMSException("The destination "+destination+" does not exist.");

View File

@ -31,6 +31,7 @@ import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.Connection;
import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.DestinationAlreadyExistsException;
import org.apache.activemq.broker.region.policy.PendingDurableSubscriberMessageStoragePolicy;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.broker.region.policy.VMPendingDurableSubscriberMessageStoragePolicy;
@ -244,7 +245,7 @@ public class RegionBroker implements Broker {
public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception {
if( destinations.contains(destination) ){
throw new JMSException("Destination already exists: "+destination);
throw new DestinationAlreadyExistsException(destination);
}
Destination answer = null;
switch(destination.getDestinationType()) {