mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-3401 - pluggable unresolved destination trnasformer
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1162073 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4f50d25a22
commit
713dcaae56
|
@ -71,6 +71,8 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da
|
|||
protected transient boolean isPattern;
|
||||
protected transient int hashValue;
|
||||
protected Map<String, String> options;
|
||||
|
||||
protected static UnresolvedDestinationTransformer unresolvableDestinationTransformer = new DefaultUnresolvedDestinationTransformer();
|
||||
|
||||
public ActiveMQDestination() {
|
||||
}
|
||||
|
@ -127,8 +129,9 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da
|
|||
return new ActiveMQQueue(queueName);
|
||||
} else if (queueName == null && topicName != null) {
|
||||
return new ActiveMQTopic(topicName);
|
||||
} else {
|
||||
return unresolvableDestinationTransformer.transform(dest);
|
||||
}
|
||||
throw new JMSException("Could no disambiguate on queue|Topic-name totransform pollymorphic destination into a ActiveMQ destination: " + dest);
|
||||
}
|
||||
if (dest instanceof TemporaryQueue) {
|
||||
return new ActiveMQTempQueue(((TemporaryQueue)dest).getQueueName());
|
||||
|
@ -379,4 +382,12 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da
|
|||
public boolean isPattern() {
|
||||
return isPattern;
|
||||
}
|
||||
|
||||
public static UnresolvedDestinationTransformer getUnresolvableDestinationTransformer() {
|
||||
return unresolvableDestinationTransformer;
|
||||
}
|
||||
|
||||
public static void setUnresolvableDestinationTransformer(UnresolvedDestinationTransformer unresolvableDestinationTransformer) {
|
||||
ActiveMQDestination.unresolvableDestinationTransformer = unresolvableDestinationTransformer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* 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.command;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Topic;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class DefaultUnresolvedDestinationTransformer implements UnresolvedDestinationTransformer {
|
||||
|
||||
@Override
|
||||
public ActiveMQDestination transform(Destination dest) throws JMSException {
|
||||
String queueName = ((Queue) dest).getQueueName();
|
||||
String topicName = ((Topic) dest).getTopicName();
|
||||
|
||||
if (queueName == null && topicName == null) {
|
||||
throw new JMSException("Unresolvable destination: Both queue and topic names are null: " + dest);
|
||||
}
|
||||
try {
|
||||
Method isQueueMethod = dest.getClass().getMethod("isQueue");
|
||||
Method isTopicMethod = dest.getClass().getMethod("isTopic");
|
||||
Boolean isQueue = (Boolean) isQueueMethod.invoke(dest);
|
||||
Boolean isTopic = (Boolean) isTopicMethod.invoke(dest);
|
||||
if (isQueue) {
|
||||
return new ActiveMQQueue(queueName);
|
||||
} else if (isTopic) {
|
||||
return new ActiveMQTopic(topicName);
|
||||
} else {
|
||||
throw new JMSException("Unresolvable destination: Neither Queue nor Topic: " + dest);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new JMSException("Unresolvable destination: " + e.getMessage() + ": " + dest);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* 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.command;
|
||||
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
|
||||
public interface UnresolvedDestinationTransformer {
|
||||
|
||||
public ActiveMQDestination transform(Destination dest) throws JMSException;
|
||||
|
||||
}
|
Loading…
Reference in New Issue