From 833eefb3455efef6ed0f412b8f60fdb1686a56f5 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 27 Sep 2006 14:19:44 +0000 Subject: [PATCH] ensure that producer & consumers are created lazily git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@450451 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/activemq/network/jms/QueueBridge.java | 7 +++++-- .../java/org/apache/activemq/network/jms/TopicBridge.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java index 7e8ab67c64..ab47580674 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java @@ -71,7 +71,7 @@ class QueueBridge extends DestinationBridge{ return consumer; } - protected MessageProducer createProducer() throws JMSException{ + protected synchronized MessageProducer createProducer() throws JMSException{ producerSession=producerConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE); producer = producerSession.createSender(null); return producer; @@ -80,7 +80,10 @@ class QueueBridge extends DestinationBridge{ - protected void sendMessage(Message message) throws JMSException{ + protected synchronized void sendMessage(Message message) throws JMSException{ + if (producer == null) { + createProducer(); + } producer.send(producerQueue,message); } diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java index 9f45f3ee5e..2325dc8f3b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java @@ -79,13 +79,16 @@ class TopicBridge extends DestinationBridge{ - protected MessageProducer createProducer() throws JMSException{ + protected synchronized MessageProducer createProducer() throws JMSException{ producerSession=producerConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); producer = producerSession.createPublisher(null); return producer; } - protected void sendMessage(Message message) throws JMSException{ + protected synchronized void sendMessage(Message message) throws JMSException{ + if (producer == null) { + createProducer(); + } producer.publish(producerTopic,message); }