camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r772859 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/processor/async/ component...
Date Fri, 08 May 2009 06:33:12 GMT
Author: davsclaus
Date: Fri May  8 06:33:12 2009
New Revision: 772859

URL: http://svn.apache.org/viewvc?rev=772859&view=rev
Log:
CAMEL-1572: Improvements to asynd DSL.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/WaitForTaskToComplete.java   (with
props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/AsyncProcessor.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDefaultErrorHandlerTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitWithErrorTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitTest.xml
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitWithErrorTest.xml

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/WaitForTaskToComplete.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/WaitForTaskToComplete.java?rev=772859&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/WaitForTaskToComplete.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/WaitForTaskToComplete.java Fri May
 8 06:33:12 2009
@@ -0,0 +1,36 @@
+/**
+ * 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;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * Represent the kinds of options for wait for tasks to complete.
+ * <p/>
+ * The tasks is usually async tasks executed by the JDK concurrency library.
+ * With these options the caller can choose whether to wait for the task to complete
+ * or not before the caller thread continues.
+ *
+ * @version $Revision$
+ */
+@XmlType
+@XmlEnum(String.class)
+public enum WaitForTaskToComplete {
+
+    Newer, IfReplyExpected, Always
+}

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

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/WaitForTaskToComplete.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/AsyncDefinition.java Fri May
 8 06:33:12 2009
@@ -24,6 +24,7 @@
 import javax.xml.bind.annotation.XmlTransient;
 
 import org.apache.camel.Processor;
+import org.apache.camel.WaitForTaskToComplete;
 import org.apache.camel.processor.AsyncProcessor;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.util.concurrent.ExecutorServiceHelper;
@@ -44,7 +45,7 @@
     @XmlAttribute(required = false)
     private Integer poolSize;
     @XmlAttribute(required = false)
-    private Boolean waitForTaskToComplete = Boolean.TRUE;
+    private WaitForTaskToComplete waitForTaskToComplete = WaitForTaskToComplete.Always;
 
     @Override
     public Processor createProcessor(RouteContext routeContext) throws Exception {
@@ -98,11 +99,11 @@
      * <p/>
      * Is default <tt>true</tt>
      *
-     * @param complete whether to wait or not
+     * @param wait the wait option
      * @return the builder
      */
-    public AsyncDefinition waitForTaskToComplete(boolean complete) {
-        setWaitForTaskToComplete(complete);
+    public AsyncDefinition waitForTaskToComplete(WaitForTaskToComplete wait) {
+        setWaitForTaskToComplete(wait);
         return this;
     }
 
@@ -122,11 +123,11 @@
         this.poolSize = poolSize;
     }
 
-    public Boolean getWaitForTaskToComplete() {
+    public WaitForTaskToComplete getWaitForTaskToComplete() {
         return waitForTaskToComplete;
     }
 
-    public void setWaitForTaskToComplete(Boolean waitForTaskToComplete) {
+    public void setWaitForTaskToComplete(WaitForTaskToComplete waitForTaskToComplete) {
         this.waitForTaskToComplete = waitForTaskToComplete;
     }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Fri
May  8 06:33:12 2009
@@ -675,14 +675,12 @@
      * contain a {@link java.util.concurrent.Future} handle so you can get the real response
      * later using this handle.
      * <p/>
-     * Will default wait for the async route to complete, but this behavior can be overriden
by:
+     * Will default <tt>Always</tt> wait for the async route to complete, but
this behavior can be overriden by:
      * <ul>
-     *   <li>configuring the {@link org.apache.camel.model.AsyncDefinition#waitForTaskToComplete(boolean)}
-     * method to <tt>false</tt></li>
-     *   <li>or setting a IN message header with the key {@link org.apache.camel.Exchange#ASYNC_WAIT}
-     * to <tt>false</tt>.</li>
+     *   <li>Configuring the <tt>waitForTaskToComplete</tt> option</li>
+     *   <li>Provide an IN header with the key {@link org.apache.camel.Exchange#ASYNC_WAIT}
with the
+     * value containing a type {@link org.apache.camel.WaitForTaskToComplete}. The header
will take precedence, if provided.</li>
      * </ul>
-     * The header will take precedence, also if its <tt>true</tt>
      *
      * @return the builder
      */
@@ -700,10 +698,10 @@
      * <p/>
      * Will default wait for the async route to complete, but this behavior can be overriden
by:
      * <ul>
-     *   <li>configuring the {@link org.apache.camel.model.AsyncDefinition#waitForTaskToComplete(boolean)}
-     * method to <tt>false</tt></li>
+     *   <li>Configuring the <tt>waitForTaskToComplete</tt> option</li>
+     *   <li>Provide an IN header with the key {@link org.apache.camel.Exchange#ASYNC_WAIT}
with the
+     * value containing a type {@link org.apache.camel.WaitForTaskToComplete}. The header
will take precedence, if provided.</li>
      * </ul>
-     * The header will take precedence, also if its <tt>true</tt>
      *
      * @param poolSize the core pool size
      * @return the builder

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/AsyncProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/AsyncProcessor.java?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/AsyncProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/AsyncProcessor.java Fri
May  8 06:33:12 2009
@@ -22,6 +22,7 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.WaitForTaskToComplete;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.concurrent.ExecutorServiceHelper;
 
@@ -40,9 +41,9 @@
 
     private static final int DEFAULT_THREADPOOL_SIZE = 5;
     private ExecutorService executorService;
-    private boolean waitTaskComplete;
+    private WaitForTaskToComplete waitTaskComplete;
 
-    public AsyncProcessor(Processor output, ExecutorService executorService, boolean waitTaskComplete)
{
+    public AsyncProcessor(Processor output, ExecutorService executorService, WaitForTaskToComplete
waitTaskComplete) {
         super(output);
         this.executorService = executorService;
         this.waitTaskComplete = waitTaskComplete;
@@ -71,12 +72,12 @@
         Future<Exchange> future = getExecutorService().submit(task);
 
         // compute if we should wait for task to complete or not
-        boolean wait = waitTaskComplete;
+        WaitForTaskToComplete wait = waitTaskComplete;
         if (exchange.getIn().getHeader(Exchange.ASYNC_WAIT) != null) {
-            wait = exchange.getIn().getHeader(Exchange.ASYNC_WAIT, Boolean.class);
+            wait = exchange.getIn().getHeader(Exchange.ASYNC_WAIT, WaitForTaskToComplete.class);
         }
 
-        if (wait) {
+        if (wait != WaitForTaskToComplete.Newer) {
             // wait for task to complete
             Exchange response = future.get();
             ExchangeHelper.copyResults(exchange, response);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDeadLetterChannelTest.java
Fri May  8 06:33:12 2009
@@ -20,6 +20,7 @@
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.WaitForTaskToComplete;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
@@ -78,7 +79,7 @@
                 errorHandler(deadLetterChannel("mock:dead").maximumRedeliveries(2).delay(0).logStackTrace(false));
 
                 from("direct:in")
-                    .async(2).waitForTaskToComplete(false)
+                    .async(2).waitForTaskToComplete(WaitForTaskToComplete.Newer)
                     .to("mock:foo")
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDefaultErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDefaultErrorHandlerTest.java?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDefaultErrorHandlerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncDefaultErrorHandlerTest.java
Fri May  8 06:33:12 2009
@@ -20,6 +20,7 @@
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.WaitForTaskToComplete;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -67,7 +68,7 @@
             @Override
             public void configure() throws Exception {
                 from("direct:in")
-                    .async(2).waitForTaskToComplete(false)
+                    .async(2).waitForTaskToComplete(WaitForTaskToComplete.Newer)
                     .to("mock:foo")
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitTest.java?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitTest.java
Fri May  8 06:33:12 2009
@@ -22,6 +22,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
+import org.apache.camel.WaitForTaskToComplete;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -130,7 +131,7 @@
                             // we do not want to wait for tasks to be complete so we instruct
Camel
                             // to not wait, and therefore Camel returns the Future<Exchange>
handle we
                             // can use to get the result when we want
-                        .async().waitForTaskToComplete(false)
+                        .async().waitForTaskToComplete(WaitForTaskToComplete.Newer)
                             // from this point forward this is the async route doing its
work
                             // so we do a bit of delay to simulate heavy work that takes
time
                         .to("mock:foo")

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitWithErrorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitWithErrorTest.java?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitWithErrorTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/async/AsyncRouteNoWaitWithErrorTest.java
Fri May  8 06:33:12 2009
@@ -22,6 +22,7 @@
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.WaitForTaskToComplete;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -103,7 +104,7 @@
                             // now turn the route into async from this point forward
                             // the caller will have a Future<Exchange> returned as
response in OUT
                             // to be used to grap the async response when he fell like it
-                        .async().waitForTaskToComplete(false)
+                        .async().waitForTaskToComplete(WaitForTaskToComplete.Newer)
                             // from this point forward this is the async route doing its
work
                             // so we do a bit of delay to simulate heavy work that takes
time
                         .to("mock:foo")

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitTest.xml?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitTest.xml
Fri May  8 06:33:12 2009
@@ -30,7 +30,7 @@
                 <constant>Hello World</constant>
             </transform>
 
-            <async waitForTaskToComplete="false">
+            <async waitForTaskToComplete="Newer">
                 <to uri="mock:foo"/>
                 <delay>
                     <constant>100</constant>

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitWithErrorTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitWithErrorTest.xml?rev=772859&r1=772858&r2=772859&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitWithErrorTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/async/SpringAsyncRouteNoWaitWithErrorTest.xml
Fri May  8 06:33:12 2009
@@ -30,7 +30,7 @@
                 <constant>Hello World</constant>
             </transform>
 
-            <async waitForTaskToComplete="false">
+            <async waitForTaskToComplete="Newer">
                 <to uri="mock:foo"/>
                 <delay>
                     <constant>100</constant>



Mime
View raw message