You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2013/09/27 07:56:27 UTC

[2/3] git commit: since most of the brokers doesn't support dynamic topics creation, we should specify the topics in jndi.properties file and then lookup from the context

since most of the brokers doesn't support dynamic topics creation, we should specify the topics in jndi.properties file and then lookup from the context


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/c6776f3a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/c6776f3a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/c6776f3a

Branch: refs/heads/master
Commit: c6776f3a6a6423476bf9d61414e9e76d6cbd84ca
Parents: 0b2f481
Author: Nirmal Fernando <ni...@apache.org>
Authored: Fri Sep 27 11:22:54 2013 +0530
Committer: Nirmal Fernando <ni...@apache.org>
Committed: Fri Sep 27 11:22:54 2013 +0530

----------------------------------------------------------------------
 .../lb/common/mb/publish/TopicPublisher.java     | 18 ++++++++++++------
 .../lb/common/mb/subscribe/TopicSubscriber.java  | 19 +++++++++++++------
 2 files changed, 25 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c6776f3a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/publish/TopicPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/publish/TopicPublisher.java b/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/publish/TopicPublisher.java
index ce615dc..8e04755 100644
--- a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/publish/TopicPublisher.java
+++ b/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/publish/TopicPublisher.java
@@ -46,7 +46,7 @@ public class TopicPublisher {
 	 */
 	public TopicPublisher(String aTopicName) {
 		topicName = aTopicName;
-		connector = new TopicConnector();
+		connector = new TopicConnector(aTopicName);
 	}
 
 	/**
@@ -68,9 +68,15 @@ public class TopicPublisher {
 		
 		// closes all sessions/connections
 		try {
-			topicPublisher.close();
-			topicSession.close();
-			connector.close();
+			if (topicPublisher != null) {
+				topicPublisher.close();
+			}
+			if (topicSession != null) {
+				topicSession.close();
+			}
+			if (connector != null) {
+				connector.close();
+			}
 		} catch (JMSException ignore) {
 		}
 	}
@@ -91,8 +97,8 @@ public class TopicPublisher {
 		connector.init();
 		// get a session
 		topicSession = connector.newSession();
-		Topic topic;
-		topic = topicSession.createTopic(topicName);
+		Topic topic = connector.getTopic();
+//		topic = topicSession.createTopic(topicName);
 		topicPublisher = topicSession.createPublisher(topic);
 	}
 	

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c6776f3a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/subscribe/TopicSubscriber.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/subscribe/TopicSubscriber.java b/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/subscribe/TopicSubscriber.java
index ce11a56..99678f2 100644
--- a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/subscribe/TopicSubscriber.java
+++ b/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/mb/subscribe/TopicSubscriber.java
@@ -48,7 +48,7 @@ public class TopicSubscriber implements Runnable {
 	 */
 	public TopicSubscriber(String aTopicName) {
 		topicName = aTopicName;
-		connector = new TopicConnector();
+		connector = new TopicConnector(aTopicName);
 	}
 
 	private void doSubscribe() throws Exception, JMSException {
@@ -56,8 +56,9 @@ public class TopicSubscriber implements Runnable {
 		connector.init();
 		// get a session
 		topicSession = connector.newSession();
-		Topic topic;
-		topic = topicSession.createTopic(topicName);
+		Topic topic = connector.getTopic();
+		//since dynamic topic creation is not supported by most of the brokers
+//		topic = topicSession.createTopic(topicName);
 		topicSubscriber = topicSession.createSubscriber(topic);
 
 		topicSubscriber.setMessageListener(messageListener);
@@ -100,9 +101,15 @@ public class TopicSubscriber implements Runnable {
 				// health checker failed
 				// closes all sessions/connections
 				try {
-					topicSubscriber.close();
-					topicSession.close();
-					connector.close();
+					if (topicSubscriber != null) {
+						topicSubscriber.close();
+					}
+					if (topicSession != null) {
+						topicSession.close();
+					}
+					if (connector != null) {
+						connector.close();
+					}
 				} catch (JMSException ignore) {
 				}
 			}