From e1bc55dafed0f58b47abde3d25f3f09adcc56834 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Fri, 3 Feb 2006 19:22:40 +0000 Subject: [PATCH] separate JndiTemplate into local and outbound git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@374729 13f79535-47bb-0310-9956-ffa450edef68 --- .../network/jms/DestinationBridge.java | 4 +++ .../activemq/network/jms/JmsConnector.java | 32 +++++++++++++++---- .../network/jms/JmsQueueConnector.java | 6 ++-- .../network/jms/JmsTopicConnector.java | 6 ++-- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/DestinationBridge.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/DestinationBridge.java index a2f75dd186..ae1f4f1722 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/DestinationBridge.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/DestinationBridge.java @@ -24,6 +24,7 @@ import javax.jms.MessageListener; import javax.jms.MessageProducer; import org.apache.activemq.Service; +import org.apache.activemq.command.ActiveMQMessage; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; @@ -94,6 +95,9 @@ abstract class DestinationBridge implements Service,MessageListener{ message.setJMSReplyTo(null); } Message converted=jmsMessageConvertor.convert(message); + if (converted == message && converted instanceof ActiveMQMessage){ + converted = (Message) ((ActiveMQMessage)converted).copy(); + } sendMessage(converted); message.acknowledge(); }catch(JMSException e){ diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java index a8be81cbc3..dac25ab615 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsConnector.java @@ -38,7 +38,8 @@ import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; */ public abstract class JmsConnector implements Service{ private static final Log log=LogFactory.getLog(JmsConnector.class); - protected JndiTemplate jndiTemplate; + protected JndiTemplate jndiLocalTemplate; + protected JndiTemplate jndiOutboundTemplate; protected JmsMesageConvertor jmsMessageConvertor; private List inboundBridges = new CopyOnWriteArrayList(); private List outboundBridges = new CopyOnWriteArrayList(); @@ -67,8 +68,11 @@ public abstract class JmsConnector implements Service{ public boolean init(){ boolean result=initialized.compareAndSet(false,true); if(result){ - if(jndiTemplate==null){ - jndiTemplate=new JndiTemplate(); + if(jndiLocalTemplate==null){ + jndiLocalTemplate=new JndiTemplate(); + } + if(jndiOutboundTemplate==null){ + jndiOutboundTemplate=new JndiTemplate(); } if(jmsMessageConvertor==null){ jmsMessageConvertor=new SimpleJmsMessageConvertor(); @@ -117,16 +121,30 @@ public abstract class JmsConnector implements Service{ /** * @return Returns the jndiTemplate. */ - public JndiTemplate getJndiTemplate(){ - return jndiTemplate; + public JndiTemplate getJndiLocalTemplate(){ + return jndiLocalTemplate; } /** * @param jndiTemplate * The jndiTemplate to set. */ - public void setJndiTemplate(JndiTemplate jndiTemplate){ - this.jndiTemplate=jndiTemplate; + public void setJndiLocalTemplate(JndiTemplate jndiTemplate){ + this.jndiLocalTemplate=jndiTemplate; + } + + /** + * @return Returns the jndiOutboundTemplate. + */ + public JndiTemplate getJndiOutboundTemplate(){ + return jndiOutboundTemplate; + } + + /** + * @param jndiOutboundTemplate The jndiOutboundTemplate to set. + */ + public void setJndiOutboundTemplate(JndiTemplate jndiOutboundTemplate){ + this.jndiOutboundTemplate=jndiOutboundTemplate; } /** diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java index e714037a7d..9c1860d924 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsQueueConnector.java @@ -269,7 +269,7 @@ public class JmsQueueConnector extends JmsConnector{ if(outboundQueueConnectionFactory==null){ // look it up from JNDI if(outboundQueueConnectionFactoryName!=null){ - outboundQueueConnectionFactory=(QueueConnectionFactory) jndiTemplate.lookup( + outboundQueueConnectionFactory=(QueueConnectionFactory) jndiOutboundTemplate.lookup( outboundQueueConnectionFactoryName,QueueConnectionFactory.class); if(outboundUsername!=null){ outboundQueueConnection=outboundQueueConnectionFactory.createQueueConnection(outboundUsername, @@ -299,7 +299,7 @@ public class JmsQueueConnector extends JmsConnector{ if(embeddedConnectionFactory==null){ // look it up from JNDI if(localConnectionFactoryName!=null){ - localQueueConnectionFactory=(QueueConnectionFactory) jndiTemplate.lookup( + localQueueConnectionFactory=(QueueConnectionFactory) jndiLocalTemplate.lookup( localConnectionFactoryName,QueueConnectionFactory.class); if(localUsername!=null){ localQueueConnection=localQueueConnectionFactory.createQueueConnection(localUsername, @@ -418,7 +418,7 @@ public class JmsQueueConnector extends JmsConnector{ }catch(JMSException e){ //look-up the Queue try{ - result = (Queue) jndiTemplate.lookup(queueName, Queue.class); + result = (Queue) jndiOutboundTemplate.lookup(queueName, Queue.class); }catch(NamingException e1){ String errStr = "Failed to look-up Queue for name: " + queueName; log.error(errStr,e); diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java index d69415f010..a32911031c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/JmsTopicConnector.java @@ -269,7 +269,7 @@ public class JmsTopicConnector extends JmsConnector{ if(outboundTopicConnectionFactory==null){ // look it up from JNDI if(outboundTopicConnectionFactoryName!=null){ - outboundTopicConnectionFactory=(TopicConnectionFactory) jndiTemplate.lookup( + outboundTopicConnectionFactory=(TopicConnectionFactory) jndiOutboundTemplate.lookup( outboundTopicConnectionFactoryName,TopicConnectionFactory.class); if(outboundUsername!=null){ outboundTopicConnection=outboundTopicConnectionFactory.createTopicConnection(outboundUsername, @@ -299,7 +299,7 @@ public class JmsTopicConnector extends JmsConnector{ if(embeddedConnectionFactory==null){ // look it up from JNDI if(localConnectionFactoryName!=null){ - localTopicConnectionFactory=(TopicConnectionFactory) jndiTemplate.lookup( + localTopicConnectionFactory=(TopicConnectionFactory) jndiLocalTemplate.lookup( localConnectionFactoryName,TopicConnectionFactory.class); if(localUsername!=null){ localTopicConnection=localTopicConnectionFactory.createTopicConnection(localUsername, @@ -418,7 +418,7 @@ public class JmsTopicConnector extends JmsConnector{ }catch(JMSException e){ //look-up the Topic try{ - result = (Topic) jndiTemplate.lookup(topicName, Topic.class); + result = (Topic) jndiOutboundTemplate.lookup(topicName, Topic.class); }catch(NamingException e1){ String errStr = "Failed to look-up Topic for name: " + topicName; log.error(errStr,e);