public ManagementStrategy create(CamelContext context, boolean disableJMX) { ManagementStrategy answer; if (disableJMX || Boolean.getBoolean(JmxSystemPropertyKeys.DISABLED)) { answer = new DefaultManagementStrategy(context); } else { try { answer = new ManagedManagementStrategy(context, new DefaultManagementAgent(context)); // must add management lifecycle strategy context.getLifecycleStrategies().add(0, new DefaultManagementLifecycleStrategy(context)); } catch (Exception e) { log.warn("Cannot create JMX lifecycle strategy. Will fallback and disable JMX.", e); answer = new DefaultManagementStrategy(context); } } return answer; }
public void init(ManagementStrategy strategy) { super.init(strategy); this.exchangesCompleted = new Statistic("org.apache.camel.exchangesCompleted", this, Statistic.UpdateMode.COUNTER); this.exchangesFailed = new Statistic("org.apache.camel.exchangesFailed", this, Statistic.UpdateMode.COUNTER); this.exchangesInflight = new Statistic("org.apache.camel.exchangesInflight", this, Statistic.UpdateMode.COUNTER); this.failuresHandled = new Statistic("org.apache.camel.failuresHandled", this, Statistic.UpdateMode.COUNTER); this.redeliveries = new Statistic("org.apache.camel.redeliveries", this, Statistic.UpdateMode.COUNTER); this.externalRedeliveries = new Statistic("org.apache.camel.externalRedeliveries", this, Statistic.UpdateMode.COUNTER); this.minProcessingTime = new Statistic("org.apache.camel.minimumProcessingTime", this, Statistic.UpdateMode.MINIMUM); this.maxProcessingTime = new Statistic("org.apache.camel.maximumProcessingTime", this, Statistic.UpdateMode.MAXIMUM); this.totalProcessingTime = new Statistic("org.apache.camel.totalProcessingTime", this, Statistic.UpdateMode.COUNTER); this.lastProcessingTime = new Statistic("org.apache.camel.lastProcessingTime", this, Statistic.UpdateMode.VALUE); this.deltaProcessingTime = new Statistic("org.apache.camel.deltaProcessingTime", this, Statistic.UpdateMode.DELTA); this.meanProcessingTime = new Statistic("org.apache.camel.meanProcessingTime", this, Statistic.UpdateMode.VALUE); this.firstExchangeCompletedTimestamp = new Statistic("org.apache.camel.firstExchangeCompletedTimestamp", this, Statistic.UpdateMode.VALUE); this.firstExchangeFailureTimestamp = new Statistic("org.apache.camel.firstExchangeFailureTimestamp", this, Statistic.UpdateMode.VALUE); this.lastExchangeCompletedTimestamp = new Statistic("org.apache.camel.lastExchangeCompletedTimestamp", this, Statistic.UpdateMode.VALUE); this.lastExchangeFailureTimestamp = new Statistic("org.apache.camel.lastExchangeFailureTimestamp", this, Statistic.UpdateMode.VALUE); }
protected CamelContext createCamelContext() throws Exception { CamelContext camelContext = super.createCamelContext(); ShutdownStrategy shutdownStrategy = camelContext.getShutdownStrategy(); camelContext.addComponent("async", new MyAsyncComponent()); shutdownStrategy.setTimeout(1000); shutdownStrategy.setTimeUnit(TimeUnit.MILLISECONDS); shutdownStrategy.setShutdownNowOnTimeout(true); ManagementStrategy managementStrategy = new DefaultManagementStrategy(); managementStrategy.addEventNotifier(en); camelContext.setManagementStrategy(managementStrategy); return camelContext; }
public void init(ManagementStrategy strategy) { this.exchangesTotal = new Statistic("org.apache.camel.exchangesTotal", this, Statistic.UpdateMode.COUNTER); this.startTimestamp = new Statistic("org.apache.camel.startTimestamp", this, Statistic.UpdateMode.VALUE); this.resetTimestamp = new Statistic("org.apache.camel.resetTimestamp", this, Statistic.UpdateMode.VALUE); startTimestamp.updateValue(new Date().getTime()); resetTimestamp.updateValue(new Date().getTime()); }
@Override public void init(ManagementStrategy strategy) { super.init(strategy); sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : false; uri = getDefinition().getExpression().getExpression(); if (sanitize) { uri = URISupport.sanitizeUri(uri); } }
public void init(ManagementStrategy strategy) { super.init(strategy); boolean sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : false; if (sanitize) { destination = URISupport.sanitizeUri(processor.getDestination().getEndpointUri()); } else { destination = processor.getDestination().getEndpointUri(); } }
public void init(ManagementStrategy strategy) { super.init(strategy); sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : false; uri = getDefinition().getExpression().getExpression(); if (sanitize) { uri = URISupport.sanitizeUri(uri); } }
@Override public void init(ManagementStrategy strategy) { super.init(strategy); boolean enabled = context.getManagementStrategy().getManagementAgent().getStatisticsLevel() != ManagementStatisticsLevel.Off; setStatisticsEnabled(enabled); exchangesInFlightKeys.clear(); exchangesInFlightStartTimestamps.clear(); }
public void init(ManagementStrategy strategy) { super.init(strategy); sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : false; if (sanitize) { uri = URISupport.sanitizeUri(processor.getUri()); } else { uri = processor.getUri(); } }
public void init(ManagementStrategy strategy) { super.init(strategy); this.sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : false; if (sanitize) { uri = URISupport.sanitizeUri(processor.getUri()); } else { uri = processor.getUri(); } }
public static void notifyCamelContextStarting(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextStartingEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextStarted(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextStartedEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextStartupFailed(CamelContext context, Throwable cause) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextStartupFailureEvent(context, cause); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextStopping(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextStoppingEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextStopped(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextStoppedEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextStopFailed(CamelContext context, Throwable cause) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextStopFailureEvent(context, cause); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyServiceStopFailure(CamelContext context, Object service, Throwable cause) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreServiceEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createServiceStopFailureEvent(context, service, cause); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyServiceStartupFailure(CamelContext context, Object service, Throwable cause) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreServiceEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createServiceStartupFailureEvent(context, service, cause); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyRouteStarted(CamelContext context, Route route) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreRouteEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createRouteStartedEvent(route); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyRouteStopped(CamelContext context, Route route) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreRouteEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createRouteStoppedEvent(route); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyRouteAdded(CamelContext context, Route route) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreRouteEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createRouteAddedEvent(route); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyRouteRemoved(CamelContext context, Route route) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreRouteEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createRouteRemovedEvent(route); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyExchangeCreated(CamelContext context, Exchange exchange) { if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) { // do not generate events for an notify event return; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeCreatedEvent()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeCreatedEvent(exchange); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyExchangeDone(CamelContext context, Exchange exchange) { if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) { // do not generate events for an notify event return; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeCompletedEvent()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeCompletedEvent(exchange); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyExchangeFailed(CamelContext context, Exchange exchange) { if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) { // do not generate events for an notify event return; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeFailedEvent(exchange); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void 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; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeFailureHandlingEvent(exchange, failureHandler, deadLetterChannel, deadLetterUri); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void 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; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeFailureHandledEvent(exchange, failureHandler, deadLetterChannel, deadLetterUri); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void 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; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeFailedEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeRedeliveryEvent(exchange, attempt); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void 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; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeSentEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeSendingEvent(exchange, endpoint); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void 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; } ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreExchangeEvents() || notifier.isIgnoreExchangeSentEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createExchangeSentEvent(exchange, endpoint, timeTaken); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextSuspending(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextSuspendingEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextSuspended(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextSuspendedEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextResuming(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextResumingEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextResumed(CamelContext context) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextResumedEvent(context); if (event == null) { return; } doNotifyEvent(notifier, event); } }
public static void notifyCamelContextResumeFailed(CamelContext context, Throwable cause) { ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (notifier.isIgnoreCamelContextEvents()) { continue; } EventFactory factory = management.getEventFactory(); if (factory == null) { return; } EventObject event = factory.createCamelContextResumeFailureEvent(context, cause); if (event == null) { return; } doNotifyEvent(notifier, event); } }
/** * Notifies event notifiers. * * @param exchange the exchange * @param callback the callback contract for creating new events. */ public static void notifyMsg(Exchange exchange, EventNotifierCallback callback) { Assert.notNull(exchange, "the exchange must not be null"); if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) { // do not generate events for an notify event return; } CamelContext context = exchange.getContext(); ManagementStrategy management = context.getManagementStrategy(); if (management == null) { return; } List<EventNotifier> notifiers = management.getEventNotifiers(); if (notifiers == null || notifiers.isEmpty()) { return; } for (EventNotifier notifier : notifiers) { if (callback.ignore(notifier)) { continue; } // we want to have new event instance for all notifiers EventObject event = callback.createEvent(exchange); doNotifyEvent(notifier, event); } }
public void setup() throws Exception { context = new DefaultCamelContext(); context.setNameStrategy(new ExplicitCamelContextNameStrategy("myCamelContextName")); final ManagementStrategy managementStrategy = context.getManagementStrategy(); final ManagementAgent managementAgent = managementStrategy.getManagementAgent(); managementAgent.setMBeanServerDefaultDomain("org.apache.camel"); final ManagementNameStrategy managementNameStrategy = context.getManagementNameStrategy(); managementNameStrategy.setNamePattern("CustomName-#name#"); // Add a simple test route context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .routeId("first-route") .log(LoggingLevel.INFO, "First Route", "${body}") .to("mock:result"); from("direct:startOther") .routeId("other-route") .log(LoggingLevel.INFO, "Other Route", "${body}") .to("mock:resultOther"); } }); }