camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1327435 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/seda/SedaConsumer.java main/java/org/apache/camel/component/seda/SedaEndpoint.java test/java/org/apache/camel/ContextTestSupport.java
Date Wed, 18 Apr 2012 09:59:17 GMT
Author: davsclaus
Date: Wed Apr 18 09:59:17 2012
New Revision: 1327435

URL: http://svn.apache.org/viewvc?rev=1327435&view=rev
Log:
CAMEL-5184: Added pollTimeout to seda endpoint. Lowered timeout during unit testing camel-core,
to cut down about 100 secs.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java?rev=1327435&r1=1327434&r2=1327435&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
Wed Apr 18 09:59:17 2012
@@ -60,10 +60,12 @@ public class SedaConsumer extends Servic
     private AsyncProcessor processor;
     private ExecutorService executor;
     private ExceptionHandler exceptionHandler;
+    private final int pollTimeout;
 
     public SedaConsumer(SedaEndpoint endpoint, Processor processor) {
         this.endpoint = endpoint;
         this.processor = AsyncProcessorConverterHelper.convert(processor);
+        this.pollTimeout = endpoint.getPollTimeout();
     }
 
     @Override
@@ -144,7 +146,8 @@ public class SedaConsumer extends Servic
             if (getEndpoint().getCamelContext().getStatus().isStarting()) {
                 LOG.trace("CamelContext is starting so skip polling");
                 try {
-                    Thread.sleep(1000);
+                    // sleep at most 1 sec
+                    Thread.sleep(Math.min(pollTimeout, 1000));
                 } catch (InterruptedException e) {
                     LOG.debug("Sleep interrupted, are we stopping? {}", isStopping() || isStopped());
                 }
@@ -155,7 +158,8 @@ public class SedaConsumer extends Servic
             if (isSuspending() || isSuspended()) {
                 LOG.trace("Consumer is suspended so skip polling");
                 try {
-                    Thread.sleep(1000);
+                    // sleep at most 1 sec
+                    Thread.sleep(Math.min(pollTimeout, 1000));
                 } catch (InterruptedException e) {
                     LOG.debug("Sleep interrupted, are we stopping? {}", isStopping() || isStopped());
                 }
@@ -164,7 +168,8 @@ public class SedaConsumer extends Servic
 
             Exchange exchange = null;
             try {
-                exchange = queue.poll(1000, TimeUnit.MILLISECONDS);
+                // use the end user configured poll timeout
+                exchange = queue.poll(pollTimeout, TimeUnit.MILLISECONDS);
                 if (exchange != null) {
                     try {
                         // send a new copied exchange with new camel context
@@ -310,7 +315,7 @@ public class SedaConsumer extends Servic
 
         // submit needed number of tasks
         int tasks = poolSize - taskCount.get();
-        LOG.debug("Creating {} consumer tasks", tasks);
+        LOG.debug("Creating {} consumer tasks with poll timeout {} ms.", tasks, pollTimeout);
         for (int i = 0; i < tasks; i++) {
             executor.execute(this);
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java?rev=1327435&r1=1327434&r2=1327435&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
Wed Apr 18 09:59:17 2012
@@ -62,6 +62,7 @@ public class SedaEndpoint extends Defaul
     private volatile MulticastProcessor consumerMulticastProcessor;
     private volatile boolean multicastStarted;
     private boolean blockWhenFull;
+    private int pollTimeout = 1000;
 
     public SedaEndpoint() {
     }
@@ -203,6 +204,15 @@ public class SedaEndpoint extends Defaul
         this.multipleConsumers = multipleConsumers;
     }
 
+    @ManagedAttribute
+    public int getPollTimeout() {
+        return pollTimeout;
+    }
+
+    public void setPollTimeout(int pollTimeout) {
+        this.pollTimeout = pollTimeout;
+    }
+
     public boolean isSingleton() {
         return true;
     }
@@ -332,6 +342,16 @@ public class SedaEndpoint extends Defaul
     }
 
     @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        // special for unit testing where we can set a system property to make seda poll
faster
+        // and therefore also react faster upon shutdown, which makes overall testing faster
of the Camel project
+        String override = System.getProperty("CamelSedaPollTimeout", "" + getPollTimeout());
+        setPollTimeout(Integer.valueOf(override));
+    }
+
+    @Override
     protected void doShutdown() throws Exception {
         // notify component we are shutting down this endpoint
         if (getComponent() != null) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?rev=1327435&r1=1327434&r2=1327435&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java Wed Apr
18 09:59:17 2012
@@ -81,6 +81,9 @@ public abstract class ContextTestSupport
     
     @Override
     protected void setUp() throws Exception {
+        // make SEDA testing faster
+        System.setProperty("CamelSedaPollTimeout", "10");
+
         if (!useJmx()) {
             disableJMX();
         } else {
@@ -129,6 +132,7 @@ public abstract class ContextTestSupport
         }
         stopCamelContext();
         System.clearProperty(JmxSystemPropertyKeys.DISABLED);
+        System.clearProperty("CamelSedaPollTimeout");
     }
 
     /**



Mime
View raw message