camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r748469 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/dataset/ main/java/org/apache/camel/impl/ main/java/org/apache/camel/util/ test/java/org/apache/camel/processor/
Date Fri, 27 Feb 2009 10:00:11 GMT
Author: davsclaus
Date: Fri Feb 27 10:00:11 2009
New Revision: 748469

URL: http://svn.apache.org/viewvc?rev=748469&view=rev
Log:
CAMEL-1384: Better support for InOptionalOut in case the returned out is null, then we should
respect that and also regard it as no response.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteMEPOptionalOutTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java?rev=748469&r1=748468&r2=748469&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
Fri Feb 27 10:00:11 2009
@@ -20,8 +20,6 @@
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
 import org.apache.camel.processor.ThroughputLogger;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * DataSet consumer.
@@ -29,7 +27,6 @@
  * @version $Revision$
  */
 public class DataSetConsumer extends DefaultConsumer {
-    private static final transient Log LOG = LogFactory.getLog(DataSetConsumer.class);
     private DataSetEndpoint endpoint;
     private Processor reporter;
 
@@ -65,15 +62,18 @@
 
                 try {
                     long delay = endpoint.getProduceDelay();
-                    if (delay < 3) {
+                    if (delay >= 0 && delay < 3) {
                         // if no delay set then we must sleep at lest for 3 millis to avoid
concurrency
                         // issues with extremely high throughput
                         delay = 3;
                     }
-                    Thread.sleep(delay);
+                    // to allow -1 to force none delay at all
+                    if (delay > 0) {
+                        Thread.sleep(delay);
+                    }
                 } catch (InterruptedException e) {
-                    // ignore and just log to debug
-                    LOG.debug(e);
+                    Thread.currentThread().interrupt();
+                    break;
                 }
                 if (reporter != null) {
                     reporter.process(exchange);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java?rev=748469&r1=748468&r2=748469&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
Fri Feb 27 10:00:11 2009
@@ -41,8 +41,8 @@
     private static final transient Log LOG = LogFactory.getLog(DataSetEndpoint.class);
     private DataSet dataSet;
     private AtomicInteger receivedCounter = new AtomicInteger();
-    private long produceDelay = -1;
-    private long consumeDelay = -1;
+    private long produceDelay;
+    private long consumeDelay;
     private long startTime;
     private long preloadSize;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java?rev=748469&r1=748468&r2=748469&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
Fri Feb 27 10:00:11 2009
@@ -83,9 +83,8 @@
     }
 
     public Exchange send(Endpoint endpoint, Exchange exchange) {
-        Exchange convertedExchange = exchange;
-        producerCache.send(endpoint, convertedExchange);
-        return convertedExchange;
+        producerCache.send(endpoint, exchange);
+        return exchange;
     }
 
     public Exchange send(Endpoint endpoint, Processor processor) {
@@ -340,7 +339,7 @@
     }
 
     protected Endpoint resolveMandatoryEndpoint(String endpointUri) {
-        Endpoint endpoint = null;
+        Endpoint endpoint;
 
         if (isUseEndpointCache()) {
             synchronized (endpointCache) {
@@ -414,8 +413,14 @@
             boolean notOut = pattern != null && !pattern.isOutCapable();
             boolean hasOut = result.getOut(false) != null;
             if (hasOut && !notOut) {
+                // we have a response in out and the pattern is out capable
                 answer = result.getOut().getBody();
+            } else if (!hasOut && result.getPattern() == ExchangePattern.InOptionalOut)
{
+                // special case where the result is InOptionalOut and with no OUT response
+                // so we should return null to indicate this fact
+                answer = null;
             } else {
+                // use IN as the response
                 answer = result.getIn().getBody();
             }
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=748469&r1=748468&r2=748469&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Fri Feb
27 10:00:11 2009
@@ -203,6 +203,10 @@
             Message out = source.getOut(false);
             if (out != null) {
                 result.getOut(true).copyFrom(out);
+            } else if (result.getPattern() == ExchangePattern.InOptionalOut) {
+                // special case where the result is InOptionalOut and with no OUT response
+                // so we should return null to indicate this fact
+                result.setOut(null);
             } else {
                 // no results so lets copy the last input
                 // as the final processor on a pipeline might not

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteMEPOptionalOutTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteMEPOptionalOutTest.java?rev=748469&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteMEPOptionalOutTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteMEPOptionalOutTest.java
Fri Feb 27 10:00:11 2009
@@ -0,0 +1,83 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test for in optional out
+ */
+public class RouteMEPOptionalOutTest extends ContextTestSupport {
+
+    public void testHasOut() {
+        Object out = template.requestBody("direct:start", "Hi");
+        assertEquals("Bye World", out);
+    }
+
+    public void testHasNotOutForInOptionalOut() {
+        // OUT is optional in the route but we should not get a response
+        Object out = template.sendBody("direct:noout", ExchangePattern.InOptionalOut, "Hi");
+        assertEquals(null, out);
+    }
+
+    public void testHasNotOutForInOut() {
+        // OUT is optional in the route but we should still not get a response
+        Object out = template.sendBody("direct:noout", ExchangePattern.InOut, "Hi");
+        assertEquals(null, out);
+    }
+
+    public void testHasNotOutForInOnly() {
+        Object out = template.sendBody("direct:noout", ExchangePattern.InOnly, "Hi");
+        assertEquals(null, out);
+    }
+
+    public void testInOnly() {
+        Object out = template.sendBody("direct:inonly", ExchangePattern.InOnly, "Hi");
+        assertEquals("Hello World", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").setExchangePattern(ExchangePattern.InOptionalOut).process(new
Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setBody("Bye World");
+                    }
+                });
+
+                from("direct:noout").setExchangePattern(ExchangePattern.InOptionalOut).process(new
Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        // we do not set any OUT only IN
+                        exchange.getIn().setBody("Hello World");
+                    }
+                });
+
+                from("direct:inonly").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getIn().setBody("Hello World");
+                    }
+                });
+            }
+        };
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteMEPOptionalOutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteMEPOptionalOutTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message