Author: davsclaus
Date: Sun Apr 22 08:45:15 2012
New Revision: 1328818

URL: http://svn.apache.org/viewvc?rev=1328818&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/branches/camel-2.9.x/   (props changed)
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
    
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
    
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1327435

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java?rev=1328818&r1=1328817&r2=1328818&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
 Sun Apr 22 08:45:15 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
@@ -143,7 +145,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());
                 }
@@ -154,7 +157,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());
                 }
@@ -163,7 +167,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
@@ -309,7 +314,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/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java?rev=1328818&r1=1328817&r2=1328818&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
 Sun Apr 22 08:45:15 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/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?rev=1328818&r1=1328817&r2=1328818&view=diff
==============================================================================
--- 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
 (original)
+++ 
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
 Sun Apr 22 08:45:15 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");
     }
 
     /**


Reply via email to