[camel] branch master updated (28b34ab -> cc8b286)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated (28b34ab -> cc8b286)

davsclaus-2
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 28b34ab  Camel 3 migration guide: camel-rx component was removed
     new 0d6fa3f  CAMEL-14354: camel-core - Optimize unnecessary object allocations. EventHelper no longer create objects
     new 1a25fc8  CAMEL-14354: camel-core - Optimize unnecessary object allocations. ReactiveExecutor no longer creates object for callback API.
     new cc8b286  CAMEL-14354: camel-core - Optimize

The 3 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:
 .../main/java/org/apache/camel/AsyncCallback.java  |    9 +-
 .../org/apache/camel/spi/ReactiveExecutor.java     |   25 +-
 .../camel/impl/engine/DefaultReactiveExecutor.java |   14 -
 .../camel/processor/CamelInternalProcessor.java    |    2 +-
 .../apache/camel/processor/MulticastProcessor.java |    2 +-
 .../java/org/apache/camel/processor/Pipeline.java  |    2 +-
 .../processor/SharedCamelInternalProcessor.java    |    2 +-
 .../errorhandler/RedeliveryErrorHandler.java       |   10 +-
 .../java/org/apache/camel/support/EventHelper.java | 1432 +++++++++++++++++---
 .../camel/support/processor/CamelLogProcessor.java |    8 +-
 10 files changed, 1271 insertions(+), 235 deletions(-)

Reply | Threaded
Open this post in threaded view
|

[camel] 01/03: CAMEL-14354: camel-core - Optimize unnecessary object allocations. EventHelper no longer create objects

davsclaus-2
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 0d6fa3f7df94a28888a9c1399d61ad6cc3cda6ba
Author: Claus Ibsen <[hidden email]>
AuthorDate: Mon Jan 13 16:23:48 2020 +0100

    CAMEL-14354: camel-core - Optimize unnecessary object allocations. EventHelper no longer create objects
---
 .../java/org/apache/camel/support/EventHelper.java | 1432 +++++++++++++++++---
 1 file changed, 1246 insertions(+), 186 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/EventHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/EventHelper.java
index fb0b8f9..8a3e2ef 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/EventHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/EventHelper.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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.
@@ -17,247 +17,270 @@
 package org.apache.camel.support;
 
 import java.util.List;
-import java.util.function.Function;
-import java.util.function.Predicate;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
+import org.apache.camel.StatefulService;
 import org.apache.camel.spi.CamelEvent;
 import org.apache.camel.spi.EventFactory;
 import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.ManagementStrategy;
-import org.apache.camel.support.service.ServiceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Helper for easily sending event notifications in a single line of code
+ *
  */
 public final class EventHelper {
 
+    // This implementation has been optimized to be as fast and not create unnecessary objects or lambdas.
+    // So therefore there is some code that seems duplicated. But this code is used frequently during routing and should
+    // be left as-is.
+
     private static final Logger LOG = LoggerFactory.getLogger(EventHelper.class);
 
     private EventHelper() {
     }
 
     public static boolean notifyCamelContextStarting(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextStartingEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
-
-    public static boolean notifyCamelContextStarted(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextStartedEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
-
-    public static boolean notifyCamelContextStartupFailed(CamelContext context, Throwable cause) {
-        return doNotify(context,
-            factory -> factory.createCamelContextStartupFailureEvent(context, cause),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
-
-    public static boolean notifyCamelContextStopping(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextStoppingEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
-
-    public static boolean notifyCamelContextStopped(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextStoppedEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
-
-    public static boolean notifyCamelContextRoutesStarting(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextRoutesStartingEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
-
-    public static boolean notifyCamelContextRoutesStarted(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextRoutesStartedEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
 
-    public static boolean notifyCamelContextRoutesStopping(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextRoutesStoppingEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
 
-    public static boolean notifyCamelContextRoutesStopped(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextRoutesStoppedEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
 
-    public static boolean notifyCamelContextStopFailure(CamelContext context, Throwable cause) {
-        return doNotify(context,
-            factory -> factory.createCamelContextStopFailureEvent(context, cause),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
 
-    public static boolean notifyServiceStopFailure(CamelContext context, Object service, Throwable cause) {
-        return doNotify(context,
-            factory -> factory.createServiceStopFailureEvent(context, service, cause),
-            EventNotifier::isIgnoreServiceEvents);
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextStartingEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
     }
 
-    public static boolean notifyServiceStartupFailure(CamelContext context, Object service, Throwable cause) {
-        return doNotify(context,
-            factory -> factory.createServiceStartupFailureEvent(context, service, cause),
-            EventNotifier::isIgnoreServiceEvents);
-    }
+    public static boolean notifyCamelContextStarted(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
 
-    public static boolean notifyRouteStarted(CamelContext context, Route route) {
-        return doNotify(context,
-            factory -> factory.createRouteStartedEvent(route),
-            EventNotifier::isIgnoreRouteEvents);
-    }
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
 
-    public static boolean notifyRouteStopped(CamelContext context, Route route) {
-        return doNotify(context,
-            factory -> factory.createRouteStoppedEvent(route),
-            EventNotifier::isIgnoreRouteEvents);
-    }
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
 
-    public static boolean notifyRouteAdded(CamelContext context, Route route) {
-        return doNotify(context,
-            factory -> factory.createRouteAddedEvent(route),
-            EventNotifier::isIgnoreRouteEvents);
-    }
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
 
-    public static boolean notifyRouteRemoved(CamelContext context, Route route) {
-        return doNotify(context,
-            factory -> factory.createRouteRemovedEvent(route),
-            EventNotifier::isIgnoreRouteEvents);
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextStartedEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
     }
 
-    public static boolean notifyExchangeCreated(CamelContext context, Exchange exchange) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeCreatedEvent(exchange),
-            EventNotifier::isIgnoreExchangeCreatedEvent);
-    }
+    public static boolean notifyCamelContextStartupFailed(CamelContext context, Throwable cause) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
 
-    public static boolean notifyExchangeDone(CamelContext context, Exchange exchange) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeCompletedEvent(exchange),
-            EventNotifier::isIgnoreExchangeCompletedEvent);
-    }
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
 
-    public static boolean notifyExchangeFailed(CamelContext context, Exchange exchange) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeFailedEvent(exchange),
-            EventNotifier::isIgnoreExchangeFailedEvents);
-    }
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
 
-    public static boolean notifyExchangeFailureHandling(CamelContext context, Exchange exchange, Processor failureHandler,
-                                                     boolean deadLetterChannel, String deadLetterUri) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeFailureHandlingEvent(exchange, failureHandler, deadLetterChannel, deadLetterUri),
-            EventNotifier::isIgnoreExchangeFailedEvents);
-    }
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
 
-    public static boolean notifyExchangeFailureHandled(CamelContext context, Exchange exchange, Processor failureHandler,
-                                                    boolean deadLetterChannel, String deadLetterUri) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeFailureHandledEvent(exchange, failureHandler, deadLetterChannel, deadLetterUri),
-            EventNotifier::isIgnoreExchangeFailedEvents);
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextStartupFailureEvent(context, cause);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
     }
 
-    public static boolean notifyExchangeRedelivery(CamelContext context, Exchange exchange, int attempt) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeRedeliveryEvent(exchange, attempt),
-            EventNotifier::isIgnoreExchangeRedeliveryEvents);
-    }
+    public static boolean notifyCamelContextStopping(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
 
-    public static boolean notifyExchangeSending(CamelContext context, Exchange exchange, Endpoint endpoint) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeSendingEvent(exchange, endpoint),
-            EventNotifier::isIgnoreExchangeSendingEvents);
-    }
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
 
-    public static boolean notifyExchangeSent(CamelContext context, Exchange exchange, Endpoint endpoint, long timeTaken) {
-        return doNotifyExchange(context, exchange,
-            factory -> factory.createExchangeSentEvent(exchange, endpoint, timeTaken),
-            EventNotifier::isIgnoreExchangeSentEvents);
-    }
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
 
-    public static boolean notifyStepStarted(CamelContext context, Exchange exchange, String stepId) {
-        return doNotifyStep(context, exchange,
-            factory -> factory.createStepStartedEvent(exchange, stepId),
-            EventNotifier::isIgnoreStepEvents);
-    }
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
 
-    public static boolean notifyStepDone(CamelContext context, Exchange exchange, String stepId) {
-        return doNotifyStep(context, exchange,
-            factory -> factory.createStepCompletedEvent(exchange, stepId),
-            EventNotifier::isIgnoreStepEvents);
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextStoppingEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
     }
 
-    public static boolean notifyStepFailed(CamelContext context, Exchange exchange, String stepId) {
-        return doNotifyStep(context, exchange,
-            factory -> factory.createStepFailedEvent(exchange, stepId),
-            EventNotifier::isIgnoreStepEvents);
-    }
+    public static boolean notifyCamelContextStopped(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
 
-    public static boolean notifyCamelContextSuspending(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextSuspendingEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
 
-    public static boolean notifyCamelContextSuspended(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextSuspendedEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
 
-    public static boolean notifyCamelContextResuming(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextResumingEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
 
-    public static boolean notifyCamelContextResumed(CamelContext context) {
-        return doNotify(context,
-            factory -> factory.createCamelContextResumedEvent(context),
-            EventNotifier::isIgnoreCamelContextEvents);
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextStoppedEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
     }
 
-    public static boolean notifyCamelContextResumeFailed(CamelContext context, Throwable cause) {
-        return doNotify(context,
-            factory -> factory.createCamelContextResumeFailureEvent(context, cause),
-            EventNotifier::isIgnoreCamelContextEvents);
-    }
+    public static boolean notifyCamelContextStopFailed(CamelContext context, Throwable cause) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
 
-    private static boolean doNotifyExchange(CamelContext context, Exchange exchange, Function<EventFactory, CamelEvent> eventSupplier, Predicate<EventNotifier> notifierFilter) {
-        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
-            // do not generate events for an notify event
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
             return false;
         }
-        return doNotify(context,
-                eventSupplier,
-                notifierFilter.or(EventNotifier::isIgnoreExchangeEvents));
-    }
 
-    private static boolean doNotifyStep(CamelContext context, Exchange exchange, Function<EventFactory, CamelEvent> eventSupplier, Predicate<EventNotifier> notifierFilter) {
-        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
-            // do not generate events for an notify event
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
             return false;
         }
-        return doNotify(context,
-            eventSupplier,
-            notifierFilter.or(EventNotifier::isIgnoreStepEvents));
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextStopFailureEvent(context, cause);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
     }
 
-    private static boolean doNotify(CamelContext context, Function<EventFactory, CamelEvent> eventSupplier, Predicate<EventNotifier> notifierFilter) {
+    public static boolean notifyServiceStopFailure(CamelContext context, Object service, Throwable cause) {
         ManagementStrategy management = context.getManagementStrategy();
         if (management == null) {
             return false;
@@ -279,13 +302,13 @@ public final class EventHelper {
             if (notifier.isDisabled()) {
                 continue;
             }
-            if (notifierFilter.test(notifier)) {
+            if (notifier.isIgnoreServiceEvents()) {
                 continue;
             }
 
             if (event == null) {
                 // only create event once
-                event = eventSupplier.apply(factory);
+                event = factory.createServiceStopFailureEvent(context, service, cause);
                 if (event == null) {
                     // factory could not create event so exit
                     return false;
@@ -296,9 +319,1046 @@ public final class EventHelper {
         return answer;
     }
 
-    private static boolean doNotifyEvent(EventNotifier notifier, CamelEvent event) {
-        // only notify if notifier is started
-        if (!ServiceHelper.isStarted(notifier)) {
+    public static boolean notifyServiceStartupFailure(CamelContext context, Object service, Throwable cause) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreServiceEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createServiceStartupFailureEvent(context, service, cause);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyRouteStarted(CamelContext context, Route route) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreRouteEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createRouteStartedEvent(route);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyRouteStopped(CamelContext context, Route route) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreRouteEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createRouteStoppedEvent(route);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyRouteAdded(CamelContext context, Route route) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreRouteEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createRouteAddedEvent(route);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyRouteRemoved(CamelContext context, Route route) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreRouteEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createRouteRemovedEvent(route);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeCreated(CamelContext context, Exchange exchange) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeCreatedEvent()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeCreatedEvent(exchange);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeDone(CamelContext context, Exchange exchange) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeCompletedEvent()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeCompletedEvent(exchange);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeFailed(CamelContext context, Exchange exchange) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeFailedEvent(exchange);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeFailureHandling(CamelContext context, Exchange exchange, Processor failureHandler,
+                                                        boolean deadLetterChannel, String deadLetterUri) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeFailureHandlingEvent(exchange, failureHandler, deadLetterChannel, deadLetterUri);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeFailureHandled(CamelContext context, Exchange exchange, Processor failureHandler,
+                                                       boolean deadLetterChannel, String deadLetterUri) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeFailureHandledEvent(exchange, failureHandler, deadLetterChannel, deadLetterUri);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeRedelivery(CamelContext context, Exchange exchange, int attempt) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeRedeliveryEvent(exchange, attempt);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeSending(CamelContext context, Exchange exchange, Endpoint endpoint) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeSendingEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeSendingEvent(exchange, endpoint);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyExchangeSent(CamelContext context, Exchange exchange, Endpoint endpoint, long timeTaken) {
+        if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
+            // do not generate events for an notify event
+            return false;
+        }
+
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        // optimise for loop using index access to avoid creating iterator object
+        for (int i = 0; i < notifiers.size(); i++) {
+            EventNotifier notifier = notifiers.get(i);
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeSentEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createExchangeSentEvent(exchange, endpoint, timeTaken);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextSuspending(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextSuspendingEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextSuspended(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextSuspendedEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextResuming(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextResumingEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextResumed(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextResumedEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextResumeFailed(CamelContext context, Throwable cause) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextResumeFailureEvent(context, cause);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextRoutesStarting(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextRoutesStartingEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextRoutesStarted(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextRoutesStartedEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextRoutesStopping(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextRoutesStoppingEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyCamelContextRoutesStopped(CamelContext context) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreCamelContextEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createCamelContextRoutesStoppedEvent(context);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyStepStarted(CamelContext context, Exchange exchange, String stepId) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreStepEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createStepStartedEvent(exchange, stepId);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyStepDone(CamelContext context, Exchange exchange, String stepId) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreStepEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createStepCompletedEvent(exchange, stepId);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    public static boolean notifyStepFailed(CamelContext context, Exchange exchange, String stepId) {
+        ManagementStrategy management = context.getManagementStrategy();
+        if (management == null) {
+            return false;
+        }
+
+        EventFactory factory = management.getEventFactory();
+        if (factory == null) {
+            return false;
+        }
+
+        List<EventNotifier> notifiers = management.getEventNotifiers();
+        if (notifiers == null || notifiers.isEmpty()) {
+            return false;
+        }
+
+        boolean answer = false;
+        CamelEvent event = null;
+        for (EventNotifier notifier : notifiers) {
+            if (notifier.isDisabled()) {
+                continue;
+            }
+            if (notifier.isIgnoreStepEvents()) {
+                continue;
+            }
+
+            if (event == null) {
+                // only create event once
+                event = factory.createStepFailedEvent(exchange, stepId);
+                if (event == null) {
+                    // factory could not create event so exit
+                    return false;
+                }
+            }
+            answer |= doNotifyEvent(notifier, event);
+        }
+        return answer;
+    }
+
+    private static boolean doNotifyEvent(EventNotifier notifier, CamelEvent event) {
+        // only notify if notifier is started
+        boolean started = true;
+        if (notifier instanceof StatefulService) {
+            started = ((StatefulService) notifier).isStarted();
+        }
+        if (!started) {
             LOG.debug("Ignoring notifying event {}. The EventNotifier has not been started yet: {}", event, notifier);
             return false;
         }
@@ -317,4 +1377,4 @@ public final class EventHelper {
         return true;
     }
 
-}
+}
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[camel] 02/03: CAMEL-14354: camel-core - Optimize unnecessary object allocations. ReactiveExecutor no longer creates object for callback API.

davsclaus-2
In reply to this post by davsclaus-2
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 1a25fc8175b8fd9464ba1e44c69b61b161d7ba07
Author: Claus Ibsen <[hidden email]>
AuthorDate: Mon Jan 13 17:13:21 2020 +0100

    CAMEL-14354: camel-core - Optimize unnecessary object allocations. ReactiveExecutor no longer creates object for callback API.
---
 .../main/java/org/apache/camel/AsyncCallback.java  |  9 +++++++-
 .../org/apache/camel/spi/ReactiveExecutor.java     | 25 +++-------------------
 .../camel/impl/engine/DefaultReactiveExecutor.java | 14 ------------
 .../camel/processor/CamelInternalProcessor.java    |  2 +-
 .../apache/camel/processor/MulticastProcessor.java |  2 +-
 .../java/org/apache/camel/processor/Pipeline.java  |  2 +-
 .../processor/SharedCamelInternalProcessor.java    |  2 +-
 .../errorhandler/RedeliveryErrorHandler.java       | 10 ++++-----
 8 files changed, 20 insertions(+), 46 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/AsyncCallback.java b/core/camel-api/src/main/java/org/apache/camel/AsyncCallback.java
index 2d9f33f..d0c3e5d 100644
--- a/core/camel-api/src/main/java/org/apache/camel/AsyncCallback.java
+++ b/core/camel-api/src/main/java/org/apache/camel/AsyncCallback.java
@@ -25,7 +25,7 @@ package org.apache.camel;
  * routing {@link Exchange} when all the data has been gathered. This allows to build non blocking
  * request/reply communication.
  */
-public interface AsyncCallback {
+public interface AsyncCallback extends Runnable {
 
     /**
      * This method is invoked once the {@link Exchange} is done.
@@ -38,4 +38,11 @@ public interface AsyncCallback {
      */
     void done(boolean doneSync);
 
+    /**
+     * Optimized for the reactive executor engine to be able to schedule this callback in its engine.
+     */
+    @Override
+    default void run() {
+        done(false);
+    }
 }
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/ReactiveExecutor.java b/core/camel-api/src/main/java/org/apache/camel/spi/ReactiveExecutor.java
index fc3c4de..eb0df12 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/ReactiveExecutor.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/ReactiveExecutor.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.spi;
 
-import org.apache.camel.AsyncCallback;
-
 /**
  * SPI to plugin different reactive engines in the Camel routing engine.
  */
@@ -36,6 +34,7 @@ public interface ReactiveExecutor {
      * @param runnable    the task
      * @param description a human readable description for logging purpose
      */
+    @Deprecated
     void schedule(Runnable runnable, String description);
 
     /**
@@ -51,6 +50,7 @@ public interface ReactiveExecutor {
      * @param runnable    the task
      * @param description a human readable description for logging purpose
      */
+    @Deprecated
     void scheduleMain(Runnable runnable, String description);
 
     /**
@@ -66,6 +66,7 @@ public interface ReactiveExecutor {
      * @param runnable    the task
      * @param description a human readable description for logging purpose
      */
+    @Deprecated
     void scheduleSync(Runnable runnable, String description);
 
     /**
@@ -75,24 +76,4 @@ public interface ReactiveExecutor {
      */
     boolean executeFromQueue();
 
-    /**
-     * Schedules the callback to be run
-     *
-     * @param callback    the callable
-     */
-    default void callback(AsyncCallback callback) {
-        schedule(new Runnable() {
-
-            @Override
-            public void run() {
-                callback.done(false);
-            }
-
-            @Override
-            public String toString() {
-                return "Callback[" + callback + "]";
-            }
-        });
-    }
-
 }
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java
index 7be0a46..b12b8f4 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultReactiveExecutor.java
@@ -110,20 +110,6 @@ public class DefaultReactiveExecutor extends ServiceSupport implements ReactiveE
         return pendingTasks.get();
     }
 
-    @Override
-    public void callback(AsyncCallback callback) {
-        schedule(new Runnable() {
-            @Override
-            public void run() {
-                callback.done(false);
-            }
-            @Override
-            public String toString() {
-                return "Callback[" + callback + "]";
-            }
-        });
-    }
-
     private static Runnable describe(Runnable runnable, String description) {
         return new Runnable() {
             @Override
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java b/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
index 7f273cc..a685085 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
@@ -180,7 +180,7 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor {
                 // CAMEL END USER - DEBUG ME HERE +++ START +++
                 // ----------------------------------------------------------
                 // callback must be called
-                exchange.getContext().getReactiveExecutor().callback(originalCallback);
+                exchange.getContext().getReactiveExecutor().schedule(originalCallback);
                 // ----------------------------------------------------------
                 // CAMEL END USER - DEBUG ME HERE +++ END +++
                 // ----------------------------------------------------------
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/MulticastProcessor.java b/core/camel-base/src/main/java/org/apache/camel/processor/MulticastProcessor.java
index 3c00670..6a918ed 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/MulticastProcessor.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/MulticastProcessor.java
@@ -547,7 +547,7 @@ public class MulticastProcessor extends AsyncProcessorSupport implements Navigat
             original.setProperty(Exchange.REDELIVERY_EXHAUSTED, exhaust);
         }
 
-        camelContext.getReactiveExecutor().callback(callback);
+        camelContext.getReactiveExecutor().schedule(callback);
     }
 
     /**
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/Pipeline.java b/core/camel-base/src/main/java/org/apache/camel/processor/Pipeline.java
index 2aa26f0..e646a45 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/Pipeline.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/Pipeline.java
@@ -110,7 +110,7 @@ public class Pipeline extends AsyncProcessorSupport implements Navigate<Processo
             // we could also consider logging the original and the nextExchange then we have *before* and *after* snapshots
             log.trace("Processing complete for exchangeId: {} >>> {}", exchange.getExchangeId(), exchange);
 
-            camelContext.getReactiveExecutor().callback(callback);
+            camelContext.getReactiveExecutor().schedule(callback);
         }
     }
 
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java b/core/camel-base/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
index 4eaa6a7..a278187 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/SharedCamelInternalProcessor.java
@@ -254,7 +254,7 @@ public class SharedCamelInternalProcessor {
                 // CAMEL END USER - DEBUG ME HERE +++ START +++
                 // ----------------------------------------------------------
                 // callback must be called
-                exchange.getContext().getReactiveExecutor().callback(callback);
+                exchange.getContext().getReactiveExecutor().schedule(callback);
                 // ----------------------------------------------------------
                 // CAMEL END USER - DEBUG ME HERE +++ END +++
                 // ----------------------------------------------------------
diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index f6a2721..6d3467a 100644
--- a/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ b/core/camel-base/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -464,7 +464,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
                             // mark the exchange to stop continue routing when interrupted
                             // as we do not want to continue routing (for example a task has been cancelled)
                             exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
-                            camelContext.getReactiveExecutor().callback(callback);
+                            camelContext.getReactiveExecutor().schedule(callback);
                         }
                     }
                 } else {
@@ -477,7 +477,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
                     // only process if the exchange hasn't failed
                     // and it has not been handled by the error processor
                     if (isDone(exchange)) {
-                        camelContext.getReactiveExecutor().callback(callback);
+                        camelContext.getReactiveExecutor().schedule(callback);
                     } else {
                         // error occurred so loop back around which we do by invoking the processAsyncErrorHandler
                         camelContext.getReactiveExecutor().schedule(this);
@@ -558,7 +558,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
                 // only process if the exchange hasn't failed
                 // and it has not been handled by the error processor
                 if (isDone(exchange)) {
-                    camelContext.getReactiveExecutor().callback(callback);
+                    camelContext.getReactiveExecutor().schedule(callback);
                     return;
                 } else {
                     // error occurred so loop back around which we do by invoking the processAsyncErrorHandler
@@ -846,7 +846,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
                         EventHelper.notifyExchangeFailureHandled(exchange.getContext(), exchange, processor, deadLetterChannel, deadLetterUri);
                     } finally {
                         // if the fault was handled asynchronously, this should be reflected in the callback as well
-                        camelContext.getReactiveExecutor().callback(callback);
+                        camelContext.getReactiveExecutor().schedule(callback);
                     }
                 });
             } else {
@@ -865,7 +865,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
                     prepareExchangeAfterFailure(exchange, isDeadLetterChannel, shouldHandle, shouldContinue);
                 } finally {
                     // callback we are done
-                    camelContext.getReactiveExecutor().callback(callback);
+                    camelContext.getReactiveExecutor().schedule(callback);
                 }
             }
 

Reply | Threaded
Open this post in threaded view
|

[camel] 03/03: CAMEL-14354: camel-core - Optimize

davsclaus-2
In reply to this post by davsclaus-2
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 cc8b2861b1de05ba61f88d8258b04ebf852c25d3
Author: Claus Ibsen <[hidden email]>
AuthorDate: Mon Jan 13 17:33:36 2020 +0100

    CAMEL-14354: camel-core - Optimize
---
 .../org/apache/camel/support/processor/CamelLogProcessor.java     | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/processor/CamelLogProcessor.java b/core/camel-support/src/main/java/org/apache/camel/support/processor/CamelLogProcessor.java
index 064b505..1656688 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/processor/CamelLogProcessor.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/processor/CamelLogProcessor.java
@@ -44,7 +44,7 @@ public class CamelLogProcessor extends AsyncProcessorSupport implements IdAware,
     private CamelLogger logger;
     private ExchangeFormatter formatter;
     private MaskingFormatter maskingFormatter;
-    private Set<LogListener> listeners;
+    private final Set<LogListener> listeners;
 
     public CamelLogProcessor() {
         this(new CamelLogger(CamelLogProcessor.class.getName()));
@@ -53,10 +53,12 @@ public class CamelLogProcessor extends AsyncProcessorSupport implements IdAware,
     public CamelLogProcessor(CamelLogger logger) {
         this.formatter = new ToStringExchangeFormatter();
         this.logger = logger;
+        this.listeners = null;
     }
 
     public CamelLogProcessor(CamelLogger logger, ExchangeFormatter formatter, MaskingFormatter maskingFormatter, Set<LogListener> listeners) {
-        this(logger);
+        this.formatter = new ToStringExchangeFormatter();
+        this.logger = logger;
         this.formatter = formatter;
         this.maskingFormatter = maskingFormatter;
         this.listeners = listeners;
@@ -124,7 +126,7 @@ public class CamelLogProcessor extends AsyncProcessorSupport implements IdAware,
     }
 
     private String fireListeners(Exchange exchange, String message) {
-        if (listeners == null) {
+        if (listeners == null || listeners.isEmpty()) {
             return message;
         }
         for (LogListener listener : listeners) {