activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r523432 - in /activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms: ConsumerType.java JmsConfiguration.java JmsEndpoint.java
Date Wed, 28 Mar 2007 18:27:53 GMT
Author: jstrachan
Date: Wed Mar 28 11:27:52 2007
New Revision: 523432

URL: http://svn.apache.org/viewvc?view=rev&rev=523432
Log:
allowd the different message listener containers to be configured; also added helper methods
to create consumers & producers using injected spring resources

Added:
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java
  (with props)
Modified:
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
    activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java

Added: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java?view=auto&rev=523432
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java
(added)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java
Wed Mar 28 11:27:52 2007
@@ -0,0 +1,8 @@
+package org.apache.camel.component.jms;
+
+/**
+ * @version $Revision$
+ */
+public enum ConsumerType {
+    Simple, Default, ServerSessionPool
+}

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/ConsumerType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?view=diff&rev=523432&r1=523431&r2=523432
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
Wed Mar 28 11:27:52 2007
@@ -24,9 +24,12 @@
 import org.springframework.jms.core.JmsTemplate102;
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
 import org.springframework.jms.listener.DefaultMessageListenerContainer;
+import org.springframework.jms.listener.DefaultMessageListenerContainer102;
 import org.springframework.jms.listener.SimpleMessageListenerContainer;
+import org.springframework.jms.listener.SimpleMessageListenerContainer102;
 import org.springframework.jms.listener.serversession.ServerSessionFactory;
 import org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer;
+import org.springframework.jms.listener.serversession.ServerSessionMessageListenerContainer102;
 import org.springframework.jms.support.converter.MessageConverter;
 import org.springframework.transaction.PlatformTransactionManager;
 
@@ -40,6 +43,7 @@
     protected static final String TRANSACTED = "TRANSACTED";
     private ConnectionFactory connectionFactory;
     private ConnectionFactory producerConnectionFactory;
+    private ConsumerType consumerType = ConsumerType.Default;
     private boolean useVersion102;
     private boolean autoStartup;
     private boolean acceptMessagesWhileStopping;
@@ -501,12 +505,27 @@
         this.priority = priority;
     }
 
+    public ConsumerType getConsumerType() {
+        return consumerType;
+    }
+
+    public void setConsumerType(ConsumerType consumerType) {
+        this.consumerType = consumerType;
+    }
+
     // Implementation methods
     //-------------------------------------------------------------------------
     protected AbstractMessageListenerContainer chooseMessageListenerContainerImplementation()
{
-        // TODO use an enum to auto-switch container types?
-
-        //return new SimpleMessageListenerContainer();
-        return new DefaultMessageListenerContainer();
+        // TODO we could allow a spring container to auto-inject these objects?
+        switch (consumerType) {
+            case Simple:
+                return isUseVersion102() ? new SimpleMessageListenerContainer102() : new
SimpleMessageListenerContainer();
+            case ServerSessionPool:
+                return isUseVersion102() ? new ServerSessionMessageListenerContainer102()
: new ServerSessionMessageListenerContainer();
+            case Default:
+                return isUseVersion102() ? new DefaultMessageListenerContainer102() : new
DefaultMessageListenerContainer();
+            default:
+                throw new IllegalArgumentException("Unknown consumer type: " + consumerType);
+        }
     }
 }

Modified: activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?view=diff&rev=523432&r1=523431&r2=523432
==============================================================================
--- activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
(original)
+++ activemq/camel/trunk/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
Wed Mar 28 11:27:52 2007
@@ -22,6 +22,7 @@
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.springframework.jms.core.JmsOperations;
+import org.springframework.jms.core.JmsTemplate;
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
 
 import javax.jms.Message;
@@ -45,12 +46,35 @@
 
     public Producer<JmsExchange> createProducer() throws Exception {
         JmsOperations template = configuration.createJmsOperations(pubSubDomain, destination);
+        return createProducer(template);
+    }
+
+    /**
+     * Creates a producer using the given template
+     */
+    public Producer<JmsExchange> createProducer(JmsOperations template) throws Exception
{
+        if (template instanceof JmsTemplate) {
+            JmsTemplate jmsTemplate = (JmsTemplate) template;
+            jmsTemplate.setPubSubDomain(pubSubDomain);
+            jmsTemplate.setDefaultDestinationName(destination);
+        }
         return startService(new JmsProducer(this, template));
     }
 
     public Consumer<JmsExchange> createConsumer(Processor<JmsExchange> processor)
throws Exception {
-
         AbstractMessageListenerContainer listenerContainer = configuration.createMessageListenerContainer();
+        return createConsumer(processor, listenerContainer);
+    }
+
+    /**
+     * Creates a consumer using the given processor and listener container
+     *
+     * @param processor the processor to use to process the messages
+     * @param listenerContainer the listener container
+     * @return a newly created consumer
+     * @throws Exception if the consumer cannot be created
+     */
+    public Consumer<JmsExchange> createConsumer(Processor<JmsExchange> processor,
AbstractMessageListenerContainer listenerContainer) throws Exception {
         listenerContainer.setDestinationName(destination);
         listenerContainer.setPubSubDomain(pubSubDomain);
 



Mime
View raw message