separate JndiTemplate into local and outbound

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@374729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-02-03 19:22:40 +00:00
parent c146def464
commit e1bc55dafe
4 changed files with 35 additions and 13 deletions

View File

@ -24,6 +24,7 @@ import javax.jms.MessageListener;
import javax.jms.MessageProducer; import javax.jms.MessageProducer;
import org.apache.activemq.Service; import org.apache.activemq.Service;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
@ -94,6 +95,9 @@ abstract class DestinationBridge implements Service,MessageListener{
message.setJMSReplyTo(null); message.setJMSReplyTo(null);
} }
Message converted=jmsMessageConvertor.convert(message); Message converted=jmsMessageConvertor.convert(message);
if (converted == message && converted instanceof ActiveMQMessage){
converted = (Message) ((ActiveMQMessage)converted).copy();
}
sendMessage(converted); sendMessage(converted);
message.acknowledge(); message.acknowledge();
}catch(JMSException e){ }catch(JMSException e){

View File

@ -38,7 +38,8 @@ import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
*/ */
public abstract class JmsConnector implements Service{ public abstract class JmsConnector implements Service{
private static final Log log=LogFactory.getLog(JmsConnector.class); private static final Log log=LogFactory.getLog(JmsConnector.class);
protected JndiTemplate jndiTemplate; protected JndiTemplate jndiLocalTemplate;
protected JndiTemplate jndiOutboundTemplate;
protected JmsMesageConvertor jmsMessageConvertor; protected JmsMesageConvertor jmsMessageConvertor;
private List inboundBridges = new CopyOnWriteArrayList(); private List inboundBridges = new CopyOnWriteArrayList();
private List outboundBridges = new CopyOnWriteArrayList(); private List outboundBridges = new CopyOnWriteArrayList();
@ -67,8 +68,11 @@ public abstract class JmsConnector implements Service{
public boolean init(){ public boolean init(){
boolean result=initialized.compareAndSet(false,true); boolean result=initialized.compareAndSet(false,true);
if(result){ if(result){
if(jndiTemplate==null){ if(jndiLocalTemplate==null){
jndiTemplate=new JndiTemplate(); jndiLocalTemplate=new JndiTemplate();
}
if(jndiOutboundTemplate==null){
jndiOutboundTemplate=new JndiTemplate();
} }
if(jmsMessageConvertor==null){ if(jmsMessageConvertor==null){
jmsMessageConvertor=new SimpleJmsMessageConvertor(); jmsMessageConvertor=new SimpleJmsMessageConvertor();
@ -117,16 +121,30 @@ public abstract class JmsConnector implements Service{
/** /**
* @return Returns the jndiTemplate. * @return Returns the jndiTemplate.
*/ */
public JndiTemplate getJndiTemplate(){ public JndiTemplate getJndiLocalTemplate(){
return jndiTemplate; return jndiLocalTemplate;
} }
/** /**
* @param jndiTemplate * @param jndiTemplate
* The jndiTemplate to set. * The jndiTemplate to set.
*/ */
public void setJndiTemplate(JndiTemplate jndiTemplate){ public void setJndiLocalTemplate(JndiTemplate jndiTemplate){
this.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;
} }
/** /**

View File

@ -269,7 +269,7 @@ public class JmsQueueConnector extends JmsConnector{
if(outboundQueueConnectionFactory==null){ if(outboundQueueConnectionFactory==null){
// look it up from JNDI // look it up from JNDI
if(outboundQueueConnectionFactoryName!=null){ if(outboundQueueConnectionFactoryName!=null){
outboundQueueConnectionFactory=(QueueConnectionFactory) jndiTemplate.lookup( outboundQueueConnectionFactory=(QueueConnectionFactory) jndiOutboundTemplate.lookup(
outboundQueueConnectionFactoryName,QueueConnectionFactory.class); outboundQueueConnectionFactoryName,QueueConnectionFactory.class);
if(outboundUsername!=null){ if(outboundUsername!=null){
outboundQueueConnection=outboundQueueConnectionFactory.createQueueConnection(outboundUsername, outboundQueueConnection=outboundQueueConnectionFactory.createQueueConnection(outboundUsername,
@ -299,7 +299,7 @@ public class JmsQueueConnector extends JmsConnector{
if(embeddedConnectionFactory==null){ if(embeddedConnectionFactory==null){
// look it up from JNDI // look it up from JNDI
if(localConnectionFactoryName!=null){ if(localConnectionFactoryName!=null){
localQueueConnectionFactory=(QueueConnectionFactory) jndiTemplate.lookup( localQueueConnectionFactory=(QueueConnectionFactory) jndiLocalTemplate.lookup(
localConnectionFactoryName,QueueConnectionFactory.class); localConnectionFactoryName,QueueConnectionFactory.class);
if(localUsername!=null){ if(localUsername!=null){
localQueueConnection=localQueueConnectionFactory.createQueueConnection(localUsername, localQueueConnection=localQueueConnectionFactory.createQueueConnection(localUsername,
@ -418,7 +418,7 @@ public class JmsQueueConnector extends JmsConnector{
}catch(JMSException e){ }catch(JMSException e){
//look-up the Queue //look-up the Queue
try{ try{
result = (Queue) jndiTemplate.lookup(queueName, Queue.class); result = (Queue) jndiOutboundTemplate.lookup(queueName, Queue.class);
}catch(NamingException e1){ }catch(NamingException e1){
String errStr = "Failed to look-up Queue for name: " + queueName; String errStr = "Failed to look-up Queue for name: " + queueName;
log.error(errStr,e); log.error(errStr,e);

View File

@ -269,7 +269,7 @@ public class JmsTopicConnector extends JmsConnector{
if(outboundTopicConnectionFactory==null){ if(outboundTopicConnectionFactory==null){
// look it up from JNDI // look it up from JNDI
if(outboundTopicConnectionFactoryName!=null){ if(outboundTopicConnectionFactoryName!=null){
outboundTopicConnectionFactory=(TopicConnectionFactory) jndiTemplate.lookup( outboundTopicConnectionFactory=(TopicConnectionFactory) jndiOutboundTemplate.lookup(
outboundTopicConnectionFactoryName,TopicConnectionFactory.class); outboundTopicConnectionFactoryName,TopicConnectionFactory.class);
if(outboundUsername!=null){ if(outboundUsername!=null){
outboundTopicConnection=outboundTopicConnectionFactory.createTopicConnection(outboundUsername, outboundTopicConnection=outboundTopicConnectionFactory.createTopicConnection(outboundUsername,
@ -299,7 +299,7 @@ public class JmsTopicConnector extends JmsConnector{
if(embeddedConnectionFactory==null){ if(embeddedConnectionFactory==null){
// look it up from JNDI // look it up from JNDI
if(localConnectionFactoryName!=null){ if(localConnectionFactoryName!=null){
localTopicConnectionFactory=(TopicConnectionFactory) jndiTemplate.lookup( localTopicConnectionFactory=(TopicConnectionFactory) jndiLocalTemplate.lookup(
localConnectionFactoryName,TopicConnectionFactory.class); localConnectionFactoryName,TopicConnectionFactory.class);
if(localUsername!=null){ if(localUsername!=null){
localTopicConnection=localTopicConnectionFactory.createTopicConnection(localUsername, localTopicConnection=localTopicConnectionFactory.createTopicConnection(localUsername,
@ -418,7 +418,7 @@ public class JmsTopicConnector extends JmsConnector{
}catch(JMSException e){ }catch(JMSException e){
//look-up the Topic //look-up the Topic
try{ try{
result = (Topic) jndiTemplate.lookup(topicName, Topic.class); result = (Topic) jndiOutboundTemplate.lookup(topicName, Topic.class);
}catch(NamingException e1){ }catch(NamingException e1){
String errStr = "Failed to look-up Topic for name: " + topicName; String errStr = "Failed to look-up Topic for name: " + topicName;
log.error(errStr,e); log.error(errStr,e);