You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/04/10 08:17:25 UTC

svn commit: r1466342 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/NotifyBuilder.java test/java/org/apache/camel/issues/NotifyBuilderExactlyDoneSplitterWhereSentToIssueTest.java

Author: davsclaus
Date: Wed Apr 10 06:17:25 2013
New Revision: 1466342

URL: http://svn.apache.org/r1466342
Log:
CAMEL-6255: Fixed NotifyBuilder whenSentTo

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderExactlyDoneSplitterWhereSentToIssueTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java?rev=1466342&r1=1466341&r2=1466342&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java Wed Apr 10 06:17:25 2013
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.EventObject;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -42,7 +44,6 @@ import org.apache.camel.support.EventNot
 import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -289,7 +290,7 @@ public class NotifyBuilder {
     public NotifyBuilder wereSentTo(final String endpointUri) {
         // insert in start of stack but after the previous wereSentTo
         stack.add(wereSentToIndex++, new EventPredicateSupport() {
-            private AtomicBoolean sentTo = new AtomicBoolean();
+            private ConcurrentMap<String, String> sentTo = new ConcurrentHashMap<String, String>();
 
             @Override
             public boolean isAbstract() {
@@ -298,16 +299,9 @@ public class NotifyBuilder {
             }
 
             @Override
-            public boolean onExchangeCreated(Exchange exchange) {
-                // reset when a new exchange is created
-                sentTo.set(false);
-                return onExchange(exchange);
-            }
-
-            @Override
             public boolean onExchangeSent(Exchange exchange, Endpoint endpoint, long timeTaken) {
                 if (EndpointHelper.matchEndpoint(context, endpoint.getEndpointUri(), endpointUri)) {
-                    sentTo.set(true);
+                    sentTo.put(exchange.getExchangeId(), exchange.getExchangeId());
                 }
                 return onExchange(exchange);
             }
@@ -315,7 +309,8 @@ public class NotifyBuilder {
             @Override
             public boolean onExchange(Exchange exchange) {
                 // filter only when sentTo
-                return sentTo.get();
+                String sent = sentTo.get(exchange.getExchangeId());
+                return sent != null;
             }
 
             public boolean matches() {
@@ -325,7 +320,7 @@ public class NotifyBuilder {
 
             @Override
             public void reset() {
-                sentTo.set(false);
+                sentTo.clear();
             }
 
             @Override

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderExactlyDoneSplitterWhereSentToIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderExactlyDoneSplitterWhereSentToIssueTest.java?rev=1466342&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderExactlyDoneSplitterWhereSentToIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/NotifyBuilderExactlyDoneSplitterWhereSentToIssueTest.java Wed Apr 10 06:17:25 2013
@@ -0,0 +1,53 @@
+/**
+ * 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 java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version
+ */
+public class NotifyBuilderExactlyDoneSplitterWhereSentToIssueTest extends ContextTestSupport {
+
+    public void testReceiveTiAnalyticsArrayOfJsonEvents() {
+        NotifyBuilder notifier = new NotifyBuilder(context)
+                .wereSentTo("stub:direct:somewhere")
+                .whenExactlyDone(7)
+                .create();
+
+        template.sendBody("direct:split", "A,B,C,D,E,F,G");
+
+        assertTrue(notifier.matches(10, TimeUnit.SECONDS));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:split")
+                    .split(body()).parallelProcessing()
+                        .log("Received: ${body}")
+                        .to("stub:direct:somewhere");
+            }
+        };
+    }
+}