You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/21 11:12:25 UTC

svn commit: r999283 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/impl/ components/camel-gae/src/main/java/org/apache/camel/component/gae/context/ components/camel-jetty/src/main/java/org/a...

Author: davsclaus
Date: Tue Sep 21 09:12:25 2010
New Revision: 999283

URL: http://svn.apache.org/viewvc?rev=999283&view=rev
Log:
CAMEL-3139: Use ActiveMQUuidGenerator by default as its faster than the Java UUID in highly concurrent systems.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/JavaUuidGeneratorTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
    camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeDefaultCamelContext.java
    camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeSpringCamelContext.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java Tue Sep 21 09:12:25 2010
@@ -39,6 +39,7 @@ public class ActiveMQUuidGenerator imple
     private static String hostName;
     private String seed;
     private final AtomicLong sequence = new AtomicLong(1);
+    private final int length;
 
     static {
         String stub = "";
@@ -72,6 +73,7 @@ public class ActiveMQUuidGenerator imple
     public ActiveMQUuidGenerator(String prefix) {
         synchronized (UNIQUE_STUB) {
             this.seed = prefix + UNIQUE_STUB + (instanceCount++) + "-";
+            this.length = seed.length() + ("" + Long.MAX_VALUE).length();
         }
     }
 
@@ -90,7 +92,10 @@ public class ActiveMQUuidGenerator imple
     }
 
     public String generateUuid() {
-        return this.seed + sequence.getAndIncrement();
+        StringBuilder sb = new StringBuilder(length);
+        sb.append(seed);
+        sb.append(sequence.getAndIncrement());
+        return sb.toString();
     }
 
     /**

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Tue Sep 21 09:12:25 2010
@@ -180,7 +180,7 @@ public class DefaultCamelContext extends
     private ShutdownRunningTask shutdownRunningTask = ShutdownRunningTask.CompleteCurrentTaskOnly;
     private ExecutorServiceStrategy executorServiceStrategy = new DefaultExecutorServiceStrategy(this);
     private Debugger debugger;
-    private UuidGenerator uuidGenerator = new JavaUuidGenerator();
+    private UuidGenerator uuidGenerator = new ActiveMQUuidGenerator();
     private final StopWatch stopWatch = new StopWatch(false);
     private Date startDate;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java Tue Sep 21 09:12:25 2010
@@ -192,9 +192,9 @@ public abstract class MessageSupport imp
         if (exchange != null) {
             uuid = exchange.getContext().getUuidGenerator().generateUuid();
         }
-        // fall back to the default UUID generator
+        // fall back to the simple UUID generator
         if (uuid == null) {
-            uuid = new JavaUuidGenerator().generateUuid();
+            uuid = new SimpleUuidGenerator().generateUuid();
         }
         return uuid;
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java Tue Sep 21 09:12:25 2010
@@ -17,17 +17,19 @@
 package org.apache.camel.impl;
 
 import junit.framework.TestCase;
+import org.apache.camel.util.StopWatch;
+import org.apache.camel.util.TimeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class ActiveMQUuidGeneratorTest extends TestCase {
     
+    private static final Log LOG = LogFactory.getLog(ActiveMQUuidGeneratorTest.class);
     private static final String PATTERN = "^ID-.*/\\d{4,5}-\\d{13}/\\d{1}-\\d{1}$";
-    private ActiveMQUuidGenerator uuidGenerator;
-
-    public void setUp() throws Exception {
-        uuidGenerator = new ActiveMQUuidGenerator();
-    }
 
     public void testGenerateUUID() {
+        ActiveMQUuidGenerator uuidGenerator = new ActiveMQUuidGenerator();
+
         String firstUUID = uuidGenerator.generateUuid();
         String secondUUID = uuidGenerator.generateUuid();
 
@@ -35,4 +37,18 @@ public class ActiveMQUuidGeneratorTest e
         assertTrue(secondUUID.matches(PATTERN));
         assertFalse(firstUUID.equals(secondUUID));
     }
+
+    public void testPerformance() {
+        ActiveMQUuidGenerator uuidGenerator = new ActiveMQUuidGenerator();
+        StopWatch watch = new StopWatch();
+
+        LOG.info("First id: " + uuidGenerator.generateUuid());
+        for (int i = 0; i < 500000; i++) {
+            uuidGenerator.generateUuid();
+        }
+        LOG.info("Last id:  " + uuidGenerator.generateUuid());
+
+        LOG.info("Took " + TimeUtils.printDuration(watch.stop()));
+    }
+
 }
\ No newline at end of file

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java Tue Sep 21 09:12:25 2010
@@ -61,7 +61,7 @@ public class DefaultCamelContextTest ext
         ctx.disableJMX();
         UuidGenerator uuidGenerator = ctx.getUuidGenerator();
         assertNotNull(uuidGenerator);
-        assertEquals(uuidGenerator.getClass(), JavaUuidGenerator.class);
+        assertEquals(uuidGenerator.getClass(), ActiveMQUuidGenerator.class);
     }
 
     public void testGetComponents() throws Exception {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/JavaUuidGeneratorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/JavaUuidGeneratorTest.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/JavaUuidGeneratorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/JavaUuidGeneratorTest.java Tue Sep 21 09:12:25 2010
@@ -17,16 +17,18 @@
 package org.apache.camel.impl;
 
 import junit.framework.TestCase;
+import org.apache.camel.util.StopWatch;
+import org.apache.camel.util.TimeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class JavaUuidGeneratorTest extends TestCase {
-    
-    private JavaUuidGenerator uuidGenerator;
 
-    public void setUp() throws Exception {
-        uuidGenerator = new JavaUuidGenerator();
-    }
+    private static final Log LOG = LogFactory.getLog(JavaUuidGeneratorTest.class);
 
     public void testGenerateUUID() {
+        JavaUuidGenerator uuidGenerator = new JavaUuidGenerator();
+
         String firstUUID = uuidGenerator.generateUuid();
         String secondUUID = uuidGenerator.generateUuid();
         
@@ -34,4 +36,17 @@ public class JavaUuidGeneratorTest exten
         assertTrue(secondUUID.matches("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$"));
         assertFalse(firstUUID.equals(secondUUID));
     }
+
+    public void testPerformance() {
+        JavaUuidGenerator uuidGenerator = new JavaUuidGenerator();
+        StopWatch watch = new StopWatch();
+
+        LOG.info("First id: " + uuidGenerator.generateUuid());
+        for (int i = 0; i < 500000; i++) {
+            uuidGenerator.generateUuid();
+        }
+        LOG.info("Last id:  " + uuidGenerator.generateUuid());
+
+        LOG.info("Took " + TimeUtils.printDuration(watch.stop()));
+    }
 }
\ No newline at end of file

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java Tue Sep 21 09:12:25 2010
@@ -17,17 +17,33 @@
 package org.apache.camel.impl;
 
 import junit.framework.TestCase;
+import org.apache.camel.util.StopWatch;
+import org.apache.camel.util.TimeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class SimpleUuidGeneratorTest extends TestCase {
     
-    private SimpleUuidGenerator uuidGenerator;
-
-    public void setUp() throws Exception {
-        uuidGenerator = new SimpleUuidGenerator();
-    }
+    private static final Log LOG = LogFactory.getLog(SimpleUuidGeneratorTest.class);
 
     public void testGenerateUUID() {
+        SimpleUuidGenerator uuidGenerator = new SimpleUuidGenerator();
+
         assertEquals("1", uuidGenerator.generateUuid());
         assertEquals("2", uuidGenerator.generateUuid());
     }
+
+    public void testPerformance() {
+        SimpleUuidGenerator uuidGenerator = new SimpleUuidGenerator();
+        StopWatch watch = new StopWatch();
+
+        LOG.info("First id: " + uuidGenerator.generateUuid());
+        for (int i = 0; i < 500000; i++) {
+            uuidGenerator.generateUuid();
+        }
+        LOG.info("Last id:  " + uuidGenerator.generateUuid());
+
+        LOG.info("Took " + TimeUtils.printDuration(watch.stop()));
+    }
+
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeDefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeDefaultCamelContext.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeDefaultCamelContext.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeDefaultCamelContext.java Tue Sep 21 09:12:25 2010
@@ -16,13 +16,22 @@
  */
 package org.apache.camel.component.gae.context;
 
+import org.apache.camel.impl.ActiveMQUuidGenerator;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.JavaUuidGenerator;
 
 public class GaeDefaultCamelContext extends DefaultCamelContext {
 
     @Override
     protected void doStart() throws Exception {
-        disableJMX(); // JMX not allowed on GAE
+        // JMX not allowed on GAE
+        disableJMX();
+
+        if (getUuidGenerator() instanceof ActiveMQUuidGenerator) {
+            // use java uuid generator as ActiveMQ uses JDK API which is not allowed on GAE
+            setUuidGenerator(new JavaUuidGenerator());
+        }
+
         super.doStart();
     }
 

Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeSpringCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeSpringCamelContext.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeSpringCamelContext.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/context/GaeSpringCamelContext.java Tue Sep 21 09:12:25 2010
@@ -19,13 +19,22 @@ package org.apache.camel.component.gae.c
 import java.util.List;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.ActiveMQUuidGenerator;
+import org.apache.camel.impl.JavaUuidGenerator;
 import org.apache.camel.spring.SpringCamelContext;
 
 public class GaeSpringCamelContext extends SpringCamelContext {
 
     @Override
     protected void doStart() throws Exception {
-        disableJMX(); // JMX not allowed on GAE
+        // JMX not allowed on GAE
+        disableJMX();
+
+        if (getUuidGenerator() instanceof ActiveMQUuidGenerator) {
+            // use java uuid generator as ActiveMQ uses JDK API which is not allowed on GAE
+            setUuidGenerator(new JavaUuidGenerator());
+        }
+
         super.doStart();
     }
 

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java (original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/DefaultJettyHttpBinding.java Tue Sep 21 09:12:25 2010
@@ -46,7 +46,7 @@ public class DefaultJettyHttpBinding imp
         Message in = exchange.getIn();
         if (!isThrowExceptionOnFailure()) {
             // if we do not use failed exception then populate response for all response codes
-            populateResponse(exchange, httpExchange, exchange.getIn(), getHeaderFilterStrategy(), responseCode);
+            populateResponse(exchange, httpExchange, in, getHeaderFilterStrategy(), responseCode);
         } else {
             if (responseCode >= 100 && responseCode < 300) {
                 // only populate response for OK response

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java (original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyContentExchange.java Tue Sep 21 09:12:25 2010
@@ -44,8 +44,6 @@ import org.eclipse.jetty.io.Buffer;
  */
 public class JettyContentExchange extends ContentExchange {
 
-    // TODO: Use the AsyncCallback API (CAMEL-2723)
-
     private static final transient Log LOG = LogFactory.getLog(JettyContentExchange.class);
 
     private final Map<String, String> headers = new LinkedHashMap<String, String>();

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java?rev=999283&r1=999282&r2=999283&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java Tue Sep 21 09:12:25 2010
@@ -18,7 +18,7 @@ package org.apache.camel.spring;
 
 import junit.framework.TestCase;
 
-import org.apache.camel.impl.JavaUuidGenerator;
+import org.apache.camel.impl.ActiveMQUuidGenerator;
 import org.apache.camel.impl.SimpleUuidGenerator;
 import org.apache.camel.spi.UuidGenerator;
 import org.springframework.context.support.StaticApplicationContext;
@@ -43,7 +43,7 @@ public class CamelContextFactoryBeanTest
         
         UuidGenerator uuidGenerator = factory.getContext().getUuidGenerator();
         
-        assertTrue(uuidGenerator instanceof JavaUuidGenerator);
+        assertTrue(uuidGenerator instanceof ActiveMQUuidGenerator);
     }
     
     public void testGetCustomUuidGenerator() throws Exception {