Author: davsclaus
Date: Wed May 23 18:58:39 2012
New Revision: 1341978
URL: http://svn.apache.org/viewvc?rev=1341978&view=rev
Log:
CAMEL-5303: Fixed in-out over seda/vm with multiConsumers enabled. Should done
when all consumers is done, and not on the first.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaMultipleConsumersIssueTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.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=1341978&r1=1341977&r2=1341978&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 May 23 18:58:39 2012
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.seda;
+import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
@@ -34,11 +35,13 @@ import org.apache.camel.impl.LoggingExce
import org.apache.camel.processor.MulticastProcessor;
import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.spi.ShutdownAware;
+import org.apache.camel.spi.Synchronization;
import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.AsyncProcessorConverterHelper;
import org.apache.camel.util.AsyncProcessorHelper;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.UnitOfWorkHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -236,7 +239,7 @@ public class SedaConsumer extends Servic
* @param exchange the exchange
* @throws Exception can be thrown if processing of the exchange failed
*/
- protected void sendToConsumers(Exchange exchange) throws Exception {
+ protected void sendToConsumers(final Exchange exchange) throws Exception {
int size = endpoint.getConsumers().size();
// if there are multiple consumers then multicast to them
@@ -250,7 +253,10 @@ public class SedaConsumer extends Servic
if (LOG.isDebugEnabled()) {
LOG.debug("Multicasting to {} consumers for Exchange: {}",
endpoint.getConsumers().size(), exchange);
}
-
+
+ // handover completions, as we need to done this when the
multicast is done
+ final List<Synchronization> completions =
exchange.handoverCompletions();
+
// use a multicast processor to process it
MulticastProcessor mp = endpoint.getConsumerMulticastProcessor();
ObjectHelper.notNull(mp, "ConsumerMulticastProcessor", this);
@@ -258,7 +264,8 @@ public class SedaConsumer extends Servic
// and use the asynchronous routing engine to support it
AsyncProcessorHelper.process(mp, exchange, new AsyncCallback() {
public void done(boolean doneSync) {
- // noop
+ // done the uow on the copy
+ UnitOfWorkHelper.doneSynchronizations(exchange,
completions, LOG);
}
});
} else {
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaMultipleConsumersIssueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaMultipleConsumersIssueTest.java?rev=1341978&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaMultipleConsumersIssueTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaMultipleConsumersIssueTest.java
Wed May 23 18:58:39 2012
@@ -0,0 +1,57 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class SedaMultipleConsumersIssueTest extends ContextTestSupport {
+
+ public void testSedaMultipleConsumersIssue() throws Exception {
+ getMockEndpoint("mock:a").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:b").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:done").expectedBodiesReceived("Hello World");
+
+ template.sendBody("direct:inbox", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:inbox")
+ .to(ExchangePattern.InOut, "vm:foo?timeout=5000")
+ .to("mock:done");
+
+ from("vm:foo?multipleConsumers=true")
+ .to("log:a")
+ .to("mock:a");
+
+ from("vm:foo?multipleConsumers=true")
+ .to("log:b")
+ .to("mock:b");
+ }
+ };
+ }
+}