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 2017/12/13 08:42:28 UTC

[camel] branch master updated (69b1033 -> f4110ee)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 69b1033  Upgrade Smack to version 4.2.2
     new 7a7a313  CAMEL-12056: Introduce NotifyBuilder.destroy()
     new f4110ee  Java 7'isms for NotifyBuilder

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/camel/builder/NotifyBuilder.java    | 40 ++++++++++++++++------
 .../apache/camel/builder/NotifyBuilderTest.java    | 39 +++++++++++++++++++++
 2 files changed, 68 insertions(+), 11 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].

[camel] 01/02: CAMEL-12056: Introduce NotifyBuilder.destroy()

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7a7a313dc9678d6155a8b7dc791fcb3c47a461f6
Author: Marc Carter <dr...@fastmail.fm>
AuthorDate: Sun Dec 3 15:14:27 2017 +0000

    CAMEL-12056: Introduce NotifyBuilder.destroy()
---
 .../org/apache/camel/builder/NotifyBuilder.java    | 21 ++++++++++--
 .../apache/camel/builder/NotifyBuilderTest.java    | 39 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
index e5933494..0fc7045 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
@@ -39,7 +39,6 @@ import org.apache.camel.management.event.ExchangeCompletedEvent;
 import org.apache.camel.management.event.ExchangeCreatedEvent;
 import org.apache.camel.management.event.ExchangeFailedEvent;
 import org.apache.camel.management.event.ExchangeSentEvent;
-import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.ObjectHelper;
@@ -64,7 +63,7 @@ public class NotifyBuilder {
     private final CamelContext context;
 
     // notifier to hook into Camel to listen for events
-    private final EventNotifier eventNotifier;
+    private final EventNotifierSupport eventNotifier;
 
     // the predicates build with this builder
     private final List<EventPredicateHolder> predicates = new ArrayList<EventPredicateHolder>();
@@ -1164,11 +1163,29 @@ public class NotifyBuilder {
      */
     public NotifyBuilder create() {
         doCreate(EventOperation.and);
+        if (eventNotifier.isStopped()) {
+            throw new IllegalStateException("A destroyed NotifyBuilder cannot be re-created.");
+        }
         created = true;
         return this;
     }
 
     /**
+     * De-registers this builder from its {@link CamelContext}.
+     * <p/>
+     * Once destroyed, this instance will not function again.
+     */
+    public void destroy() {
+        context.getManagementStrategy().removeEventNotifier(eventNotifier);
+        try {
+            ServiceHelper.stopService(eventNotifier);
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+        created = false;
+    }
+
+    /**
      * Does all the expression match?
      * <p/>
      * This operation will return immediately which means it can be used for testing at this very moment.
diff --git a/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java b/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
index 8c56713..05dd247 100644
--- a/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
+++ b/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
@@ -36,6 +36,45 @@ public class NotifyBuilderTest extends ContextTestSupport {
         }
     }
 
+    public void testDestroyUnregistersBuilder() throws Exception {
+        // Given:
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+        // When:
+        int withReg = context.getManagementStrategy().getEventNotifiers().size();
+        notify.destroy();
+        int afterDestroy = context.getManagementStrategy().getEventNotifiers().size();
+        // Then:
+        assertEquals(withReg - afterDestroy, 1);
+    }
+
+    public void testDestroyResetsBuilder() throws Exception {
+        // Given:
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+        // When:
+        notify.destroy();
+        // Then:
+        try {
+            notify.matches();
+            fail("Should have thrown an exception");
+        } catch (IllegalStateException e) {
+            assertEquals("NotifyBuilder has not been created. Invoke the create() method before matching.", e.getMessage());
+        }
+    }
+
+    public void testDestroyedBuilderCannotBeRecreated() throws Exception {
+        // Given:
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
+        // When:
+        notify.destroy();
+        // Then:
+        try {
+            notify.create();
+            fail("Should have thrown an exception");
+        } catch (IllegalStateException e) {
+            assertEquals("A destroyed NotifyBuilder cannot be re-created.", e.getMessage());
+        }
+    }
+
     public void testDirectWhenExchangeDoneSimple() throws Exception {
         NotifyBuilder notify = new NotifyBuilder(context)
                 .from("direct:foo").whenDone(1)

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.

[camel] 02/02: Java 7'isms for NotifyBuilder

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f4110ee767ae45f3588b8e4485ba4ce8b1b57c78
Author: Marc Carter <dr...@fastmail.fm>
AuthorDate: Sun Dec 3 15:34:21 2017 +0000

    Java 7'isms for NotifyBuilder
---
 .../java/org/apache/camel/builder/NotifyBuilder.java  | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
index 0fc7045..1d74bfa 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
@@ -43,6 +43,7 @@ import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
+import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,13 +67,13 @@ public class NotifyBuilder {
     private final EventNotifierSupport eventNotifier;
 
     // the predicates build with this builder
-    private final List<EventPredicateHolder> predicates = new ArrayList<EventPredicateHolder>();
+    private final List<EventPredicateHolder> predicates = new ArrayList<>();
 
     // latch to be used to signal predicates matches
     private CountDownLatch latch = new CountDownLatch(1);
 
     // the current state while building an event predicate where we use a stack and the operation
-    private final List<EventPredicate> stack = new ArrayList<EventPredicate>();
+    private final List<EventPredicate> stack = new ArrayList<>();
     private EventOperation operation;
     private boolean created;
     // keep state of how many wereSentTo we have added
@@ -251,7 +252,7 @@ public class NotifyBuilder {
      * @return the builder
      */
     public ExpressionClauseSupport<NotifyBuilder> filter() {
-        final ExpressionClauseSupport<NotifyBuilder> clause = new ExpressionClauseSupport<NotifyBuilder>(this);
+        final ExpressionClauseSupport<NotifyBuilder> clause = new ExpressionClauseSupport<>(this);
         stack.add(new EventPredicateSupport() {
 
             @Override
@@ -294,7 +295,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 ConcurrentMap<String, String> sentTo = new ConcurrentHashMap<String, String>();
+            private ConcurrentMap<String, String> sentTo = new ConcurrentHashMap<>();
 
             @Override
             public boolean isAbstract() {
@@ -1053,7 +1054,7 @@ public class NotifyBuilder {
      * @see #whenExactBodiesDone(Object...)
      */
     public NotifyBuilder whenExactBodiesDone(Object... bodies) {
-        List<Object> bodyList = new ArrayList<Object>();
+        List<Object> bodyList = new ArrayList<>();
         bodyList.addAll(Arrays.asList(bodies));
         return doWhenBodies(bodyList, false, true);
     }
@@ -1278,7 +1279,7 @@ public class NotifyBuilder {
             sb.append(eventPredicateHolder.toString());
         }
         // a crude way of skipping the first invisible operation
-        return ObjectHelper.after(sb.toString(), "().");
+        return StringHelper.after(sb.toString(), "().");
     }
 
     private void doCreate(EventOperation newOperation) {
@@ -1418,7 +1419,7 @@ public class NotifyBuilder {
     }
 
     private enum EventOperation {
-        and, or, not;
+        and, or, not
     }
 
     private interface EventPredicate {
@@ -1543,7 +1544,7 @@ public class NotifyBuilder {
      */
     private final class CompoundEventPredicate implements EventPredicate {
 
-        private List<EventPredicate> predicates = new ArrayList<EventPredicate>();
+        private List<EventPredicate> predicates = new ArrayList<>();
 
         private CompoundEventPredicate(List<EventPredicate> predicates) {
             this.predicates.addAll(predicates);
@@ -1612,7 +1613,7 @@ public class NotifyBuilder {
         public boolean onExchangeSent(Exchange exchange, Endpoint endpoint, long timeTaken) {
             for (EventPredicate predicate : predicates) {
                 boolean answer = predicate.onExchangeSent(exchange, endpoint, timeTaken);
-                LOG.trace("onExchangeSent() {} {} -> {}", new Object[]{endpoint, predicate, answer});
+                LOG.trace("onExchangeSent() {} {} -> {}", endpoint, predicate, answer);
                 if (!answer) {
                     // break at first false
                     return false;

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.