svn commit: r613143 - in /activemq/camel/trunk: ./ camel-core/src/main/java/org/apache/camel/util/ components/camel-jms/src/main/java/org/apache/camel/component/jms/ components/camel-jms/src/test/java/org/apache/camel/component/jms/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r613143 - in /activemq/camel/trunk: ./ camel-core/src/main/java/org/apache/camel/util/ components/camel-jms/src/main/java/org/apache/camel/component/jms/ components/camel-jms/src/test/java/org/apache/camel/component/jms/

jstrachan-2
Author: jstrachan
Date: Fri Jan 18 04:40:02 2008
New Revision: 613143

URL: http://svn.apache.org/viewvc?rev=613143&view=rev
Log:
moved to Spring 2.5.1 and also allowed CACHE_CONSUMER by default on newer Spring releases for https://issues.apache.org/activemq/browse/CAMEL-294

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/PackageHelper.java   (with props)
Modified:
    activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
    activemq/camel/trunk/pom.xml

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/PackageHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/PackageHelper.java?rev=613143&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/PackageHelper.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/PackageHelper.java Fri Jan 18 04:40:02 2008
@@ -0,0 +1,67 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Some helper methods for working with Java packages and versioning.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class PackageHelper {
+    public static final transient Log LOG = LogFactory.getLog(PackageHelper.class);
+
+    /**
+     * Returns true if the version number of the given package name can be found and is greater than or equal to the minimum version.
+     *
+     * For package names which include multiple dots, the dots are removed. So for example a spring version of 2.5.1 is converted to
+     * 2.51 so you can assert that its >= 2.51 (so above 2.50 and less than 2.52 etc).
+     *
+     * @param packageName the Java package name to compare
+     * @param minimumVersion the minimum version number
+     * @return true if the package name can be determined and if its greater than or equal to the minimum value
+     */
+    public static boolean isValidVersion(String packageName, double minimumVersion) {
+        try {
+            Package spring = Package.getPackage(packageName);
+            String value = spring.getImplementationVersion();
+            if (value != null) {
+                // lets remove any extra dots in the string...
+                int idx = value.indexOf('.');
+                if (idx >= 0) {
+                    StringBuffer buffer = new StringBuffer(value.substring(0, ++idx));
+                    for (int i = idx, size = value.length(); i < size; i++) {
+                        char ch = value.charAt(i);
+                        if (Character.isDigit(ch)) {
+                            buffer.append(ch);
+                        }
+                    }
+                    value = buffer.toString();
+                }
+                Double number = Double.parseDouble(value);
+                return number >= minimumVersion;
+            }
+        }
+        catch (Exception e) {
+            LOG.debug("Failed to find out " + packageName + " version: " + e, e);
+        }
+        return true;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/PackageHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?rev=613143&r1=613142&r2=613143&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java (original)
+++ activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java Fri Jan 18 04:40:02 2008
@@ -27,6 +27,7 @@
 
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.PackageHelper;
 import org.springframework.core.task.TaskExecutor;
 import org.springframework.jms.core.JmsOperations;
 import org.springframework.jms.core.JmsTemplate;
@@ -737,7 +738,8 @@
      *
      * Note that due to this
      * <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-3890">Spring Bug</a>
-     * we cannot use CACHE_CONSUMER by default which we should do as its most efficient.
+     * we cannot use CACHE_CONSUMER by default (which we should do as its most efficient)
+     * unless the spring version is 2.5.1 or later.
      * Instead we use CACHE_CONNECTION - part from for non-durable topics which must use
      * CACHE_CONSUMER to avoid missing messages (due to the consumer being created and destroyed per message).
      *
@@ -745,18 +747,24 @@
      * @param endpoint
      */
     protected int defaultCacheLevel(JmsEndpoint endpoint) {
-        if (endpoint.isPubSubDomain() && !isSubscriptionDurable()) {
-            // we must cache the consumer or we will miss messages
-            // see https://issues.apache.org/activemq/browse/CAMEL-253
+        // if we are on a new enough spring version we can assume CACHE_CONSUMER
+        if (PackageHelper.isValidVersion("org.springframework.jms", 2.51D)) {
             return DefaultMessageListenerContainer.CACHE_CONSUMER;
         }
         else {
-            // to enable consuming and sending with a single JMS session (to avoid XA) we can only use CACHE_CONNECTION
-            // due to this bug : http://opensource.atlassian.com/projects/spring/browse/SPR-3890
-            return DefaultMessageListenerContainer.CACHE_CONNECTION;
+            if (endpoint.isPubSubDomain() && !isSubscriptionDurable()) {
+                // we must cache the consumer or we will miss messages
+                // see https://issues.apache.org/activemq/browse/CAMEL-253
+                return DefaultMessageListenerContainer.CACHE_CONSUMER;
+            }
+            else {
+                // to enable consuming and sending with a single JMS session (to avoid XA) we can only use CACHE_CONNECTION
+                // due to this bug : http://opensource.atlassian.com/projects/spring/browse/SPR-3890
+                return DefaultMessageListenerContainer.CACHE_CONNECTION;
+            }
         }
     }
-    
+
     /**
      * Factory method which allows derived classes to customize the lazy
      * creation

Modified: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java?rev=613143&r1=613142&r2=613143&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java (original)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java Fri Jan 18 04:40:02 2008
@@ -25,6 +25,7 @@
 import org.apache.camel.Processor;
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 import org.springframework.jms.listener.AbstractMessageListenerContainer;
+import org.springframework.jms.listener.DefaultMessageListenerContainer;
 
 /**
  * @version $Revision: $
@@ -68,6 +69,26 @@
         EndpointMessageListener messageListener = assertIsInstanceOf(EndpointMessageListener.class, object);
         assertTrue("Should have replyToDisabled", messageListener.isDisableReplyTo());
         assertTrue("Should have isEagerLoadingOfProperties()", messageListener.isEagerLoadingOfProperties());
+    }
+
+
+    public void testCacheConsumerEnabledForQueue() throws Exception {
+        JmsEndpoint endpoint = (JmsEndpoint) resolveMandatoryEndpoint("jms:Foo.Bar");
+        assertCacheLevel(endpoint, DefaultMessageListenerContainer.CACHE_CONSUMER);
+    }
+
+    public void testCacheConsumerEnabledForTopic() throws Exception {
+        JmsEndpoint endpoint = (JmsEndpoint) resolveMandatoryEndpoint("jms:topic:Foo.Bar");
+        assertCacheLevel(endpoint, DefaultMessageListenerContainer.CACHE_CONSUMER);
+    }
+
+    protected void assertCacheLevel(JmsEndpoint endpoint, int expected) throws Exception {
+        JmsConsumer consumer = endpoint.createConsumer(dummyProcessor);
+
+        AbstractMessageListenerContainer container = consumer.getListenerContainer();
+        DefaultMessageListenerContainer defaultContainer = assertIsInstanceOf(DefaultMessageListenerContainer.class, container);
+        int cacheLevel = defaultContainer.getCacheLevel();
+        assertEquals("CacheLevel", expected, cacheLevel);
     }
 
     protected void assertDurableSubscriberEndpointIsValid(JmsEndpoint endpoint) throws Exception {

Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?rev=613143&r1=613142&r2=613143&view=diff
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Fri Jan 18 04:40:02 2008
@@ -35,12 +35,13 @@
 
   <properties>
     <camel-version>1.3-SNAPSHOT</camel-version>
+    <commons-io-version>1.3.1</commons-io-version>
     <compiler.fork>false</compiler.fork>
     <cxf-version>2.0.3-incubator</cxf-version>
-    <spring-version>2.0.6</spring-version>
+    <felix-version>1.1.0-SNAPSHOT</felix-version>
     <geronimo-spec-version>1.1</geronimo-spec-version>
-    <jetty-version>6.1.5</jetty-version>
     <httpcore-version>4.0-alpha6</httpcore-version>
+    <jetty-version>6.1.5</jetty-version>
     <m1-repo-url>scpexe://minotaur.apache.org/www/people.apache.org/repo/m1-snapshot-repository</m1-repo-url>
     <openjpa-version>0.9.6-incubating</openjpa-version>
     <release-repo-url>scpexe://people.apache.org/www/people.apache.org/repo/m2-ibiblio-rsync-repository
@@ -48,8 +49,7 @@
     <site-repo-url>scpexe://people.apache.org/www/activemq.apache.org/camel/maven/</site-repo-url>
     <slf4j-version>1.3.0</slf4j-version>
     <snapshot-repo-url>scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</snapshot-repo-url>
-    <commons-io-version>1.3.1</commons-io-version>
-    <felix-version>1.1.0-SNAPSHOT</felix-version>
+    <spring-version>2.5.1</spring-version>
     <!-- OSGi bundles properties -->
     <camel.osgi.import.pkg>!javax.xml.bind.annotation.adapters,*</camel.osgi.import.pkg>
     <camel.osgi.private.pkg>!*</camel.osgi.private.pkg>