You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/06/22 23:58:49 UTC

svn commit: r957049 - in /jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms: Utils.java client/OnMessageSubscriber.java client/Publisher.java client/ReceiveSubscriber.java sampler/FixedQueueExecutor.java sampler/Receiver.java

Author: sebb
Date: Tue Jun 22 21:58:49 2010
New Revision: 957049

URL: http://svn.apache.org/viewvc?rev=957049&view=rev
Log:
Generalise by using super interfaces

Modified:
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/FixedQueueExecutor.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java?rev=957049&r1=957048&r2=957049&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java Tue Jun 22 21:58:49 2010
@@ -21,13 +21,12 @@ package org.apache.jmeter.protocol.jms;
 import java.util.Enumeration;
 
 import javax.jms.Connection;
+import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
-import javax.jms.Queue;
 import javax.jms.Session;
-import javax.jms.Topic;
 import javax.naming.Context;
 import javax.naming.NamingException;
 
@@ -117,35 +116,36 @@ public final class Utils {
     }
 
     /**
-     * Method will lookup a given topic using JNDI.
+     * Method will lookup a given destination (topic/queue) using JNDI.
      *
      * @param context
-     * @param name the topic name
-     * @return the topic
-     * @throws NamingException if the name cannot be found as a Topic
+     * @param name the destination name
+     * @return the destination, never null
+     * @throws NamingException if the name cannot be found as a Destination
      */
-    public static Topic lookupTopic(Context context, String name) throws NamingException {
+    public static Destination lookupDestination(Context context, String name) throws NamingException {
         Object o = context.lookup(name);
-        if (o instanceof Topic){
-            return (Topic) o;
+        if (o instanceof Destination){
+            return (Destination) o;
         }
-        throw new NamingException("Found: "+name+"; expected Topic, but was: "+o.getClass().getName());
+        throw new NamingException("Found: "+name+"; expected Destination, but was: "+o.getClass().getName());
     }
 
     /**
-     * Method will lookup a given topic using JNDI.
-     *
-     * @param context
-     * @param name the Queue name
-     * @return the Queue
-     * @throws NamingException if the name cannot be found as a Queue
+     * Obtain the queue connection from the context and factory name.
+     * Does not cache the factory.
+     * @param ctx
+     * @param factoryName
+     * @return the queue connection
+     * @throws JMSException
+     * @throws NamingException
      */
-    public static Queue lookupQueue(Context context, String name) throws NamingException {
-        Object o = context.lookup(name);
-        if (o instanceof Queue){
-            return (Queue) o;
+    public static Connection getConnection(Context ctx, String factoryName) throws JMSException, NamingException {
+        Object objfac = ctx.lookup(factoryName);
+        if (objfac instanceof javax.jms.ConnectionFactory) {
+            return ((javax.jms.ConnectionFactory) objfac).createConnection();
         }
-        throw new NamingException("Found: "+name+"; expected Queue, but was: "+o.getClass().getName());
+        throw new NamingException("Expected javax.jms.ConnectionFactory, found "+objfac.getClass().getName());
     }
 
 }

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java?rev=957049&r1=957048&r2=957049&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java Tue Jun 22 21:58:49 2010
@@ -20,12 +20,12 @@ package org.apache.jmeter.protocol.jms.c
 
 import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.jms.Connection;
+import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageListener;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicSession;
+import javax.jms.Session;
 
 import org.apache.jmeter.protocol.jms.Utils;
 import org.apache.jorphan.logging.LoggingManager;
@@ -44,11 +44,9 @@ public class OnMessageSubscriber {
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
-    private final TopicConnection CONN;
+    private final Connection CONN;
 
-    private final TopicSession SESSION;
-
-    private final Topic TOPIC;
+    private final Session SESSION;
 
     private final MessageConsumer SUBSCRIBER;
 
@@ -70,10 +68,10 @@ public class OnMessageSubscriber {
     public OnMessageSubscriber(boolean useProps, String jndi, String url, String connfactory, String topic,
             boolean useAuth, String user, String pwd) throws JMSException, NamingException {
         Context ctx = InitialContextFactory.getContext(useProps, jndi, url, useAuth, user, pwd);
-        CONN = ConnectionFactory.getTopicConnection(ctx, connfactory);
-        TOPIC = Utils.lookupTopic(ctx, topic);
-        SESSION = this.CONN.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
-        SUBSCRIBER = this.SESSION.createSubscriber(this.TOPIC);
+        CONN = Utils.getConnection(ctx, connfactory);
+        Destination dest = Utils.lookupDestination(ctx, topic);
+        SESSION = CONN.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        SUBSCRIBER = SESSION.createConsumer(dest);
         log.info("created the topic connection successfully");
     }
 
@@ -89,7 +87,7 @@ public class OnMessageSubscriber {
     }
 
     /**
-     * close will close all the objects and set them to null.
+     * close will close all the objects
      */
     public void close() {
         log.info("Subscriber closed");

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java?rev=957049&r1=957048&r2=957049&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java Tue Jun 22 21:58:49 2010
@@ -21,13 +21,13 @@ package org.apache.jmeter.protocol.jms.c
 import java.io.Serializable;
 import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.jms.Connection;
+import javax.jms.Destination;
 import javax.jms.JMSException;
+import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
+import javax.jms.Session;
 import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
 
 import org.apache.jmeter.protocol.jms.Utils;
 import org.apache.jorphan.logging.LoggingManager;
@@ -37,13 +37,11 @@ public class Publisher {
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
-    private final TopicConnection connection;
+    private final Connection connection;
 
-    private final TopicSession session;
+    private final Session session;
 
-    private final Topic topic;
-
-    private final TopicPublisher publisher;
+    private final  MessageProducer producer;
 
     /**
      * Create a publisher using either the jndi.properties file or the provided parameters
@@ -64,17 +62,17 @@ public class Publisher {
         super();
         Context ctx = InitialContextFactory.getContext(useProps, initialContextFactory, 
                 providerUrl, useAuth, securityPrincipal, securityCredentials);
-        connection = ConnectionFactory.getTopicConnection(ctx, connfactory);
-        topic = Utils.lookupTopic(ctx, topicName);
-        session = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
-        publisher = session.createPublisher(topic);
+        connection = Utils.getConnection(ctx, connfactory);
+        Destination topic = Utils.lookupDestination(ctx, topicName);
+        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        producer = session.createProducer(topic);
         log.info("created the topic connection successfully");
     }
 
     public void publish(String text) {
         try {
             TextMessage msg = session.createTextMessage(text);
-            publisher.publish(msg);
+            producer.send(msg);
         } catch (JMSException e) {
             log.error(e.getMessage());
         }
@@ -83,7 +81,7 @@ public class Publisher {
     public void publish(Serializable contents) {
         try {
             ObjectMessage msg = session.createObjectMessage(contents);
-            publisher.publish(msg);
+            producer.send(msg);
         } catch (JMSException e) {
             log.error(e.getMessage());
         }
@@ -93,7 +91,7 @@ public class Publisher {
      * Close will close the session
      */
     public void close() {
-        Utils.close(publisher, log);
+        Utils.close(producer, log);
         Utils.close(session, log);
         Utils.close(connection, log);
     }

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java?rev=957049&r1=957048&r2=957049&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java Tue Jun 22 21:58:49 2010
@@ -20,13 +20,13 @@ package org.apache.jmeter.protocol.jms.c
 
 import java.util.concurrent.ConcurrentLinkedQueue;
 
+import javax.jms.Connection;
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
+import javax.jms.Session;
 import javax.jms.TextMessage;
-import javax.jms.TopicConnection;
-import javax.jms.TopicSession;
 import javax.naming.Context;
 import javax.naming.NamingException;
 
@@ -51,9 +51,9 @@ public class ReceiveSubscriber implement
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
-    private final TopicConnection CONN;
+    private final Connection CONN;
 
-    private final TopicSession SESSION;
+    private final Session SESSION;
 
     private final MessageConsumer SUBSCRIBER;
 
@@ -75,9 +75,9 @@ public class ReceiveSubscriber implement
     public ReceiveSubscriber(boolean useProps, String jndi, String url, String connfactory, String topic,
             boolean useAuth, String user, String pwd) throws NamingException, JMSException {
         Context ctx = InitialContextFactory.getContext(useProps, jndi, url, useAuth, user, pwd);
-        CONN = ConnectionFactory.getTopicConnection(ctx, connfactory);
-        Destination _topic = Utils.lookupTopic(ctx, topic);
-        SESSION = CONN.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
+        CONN = Utils.getConnection(ctx, connfactory);
+        Destination _topic = Utils.lookupDestination(ctx, topic);
+        SESSION = CONN.createSession(false, Session.AUTO_ACKNOWLEDGE);
         SUBSCRIBER = SESSION.createConsumer(_topic);
     }
 

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/FixedQueueExecutor.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/FixedQueueExecutor.java?rev=957049&r1=957048&r2=957049&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/FixedQueueExecutor.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/FixedQueueExecutor.java Tue Jun 22 21:58:49 2010
@@ -20,7 +20,7 @@ package org.apache.jmeter.protocol.jms.s
 
 import javax.jms.JMSException;
 import javax.jms.Message;
-import javax.jms.QueueSender;
+import javax.jms.MessageProducer;
 
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
@@ -38,7 +38,7 @@ public class FixedQueueExecutor implemen
     private static final Logger log = LoggingManager.getLoggerForClass();
 
     /** Sender. */
-    private final QueueSender producer;
+    private final MessageProducer producer;
 
     /** Timeout used for waiting on message. */
     private final int timeout;
@@ -55,7 +55,7 @@ public class FixedQueueExecutor implemen
      * @param useReqMsgIdAsCorrelId
      *            whether to use the request message id as the correlation id
      */
-    public FixedQueueExecutor(QueueSender producer, int timeout, boolean useReqMsgIdAsCorrelId) {
+    public FixedQueueExecutor(MessageProducer producer, int timeout, boolean useReqMsgIdAsCorrelId) {
         this.producer = producer;
         this.timeout = timeout;
         this.useReqMsgIdAsCorrelId = useReqMsgIdAsCorrelId;

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java?rev=957049&r1=957048&r2=957049&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/Receiver.java Tue Jun 22 21:58:49 2010
@@ -33,24 +33,24 @@ public class Receiver implements Runnabl
 
     private volatile boolean active;
 
-    private final QueueSession session;
+    private final Session session;
 
     private final MessageConsumer consumer;
 
-    private final QueueConnection conn;
+    private final Connection conn;
 
     private final boolean useResMsgIdAsCorrelId;
 
-    private Receiver(QueueConnectionFactory factory, Queue receiveQueue, String principal, String credentials, boolean useResMsgIdAsCorrelId) throws JMSException {
+    private Receiver(ConnectionFactory factory, Destination receiveQueue, String principal, String credentials, boolean useResMsgIdAsCorrelId) throws JMSException {
         if (null != principal && null != credentials) {
             log.info("creating receiver WITH authorisation credentials. UseResMsgId="+useResMsgIdAsCorrelId);
-            conn = factory.createQueueConnection(principal, credentials);
+            conn = factory.createConnection(principal, credentials);
         }else{
             log.info("creating receiver without authorisation credentials. UseResMsgId="+useResMsgIdAsCorrelId);
-            conn = factory.createQueueConnection(); 
+            conn = factory.createConnection(); 
         }
-        session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-        consumer = session.createReceiver(receiveQueue);
+        session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        consumer = session.createConsumer(receiveQueue);
         this.useResMsgIdAsCorrelId = useResMsgIdAsCorrelId;
         log.debug("Receiver - ctor. Starting connection now");
         conn.start();
@@ -68,7 +68,7 @@ public class Receiver implements Runnabl
      * @return the Receiver which will process the responses
      * @throws JMSException
      */
-    public static Receiver createReceiver(QueueConnectionFactory factory, Queue receiveQueue,
+    public static Receiver createReceiver(ConnectionFactory factory, Destination receiveQueue,
             String principal, String credentials, boolean useResMsgIdAsCorrelId)
             throws JMSException {
         Receiver receiver = new Receiver(factory, receiveQueue, principal, credentials, useResMsgIdAsCorrelId);



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org