Search in sources :

Example 16 with EventNotifier

use of org.apache.camel.spi.EventNotifier in project camel by apache.

the class RoutesCollector method onApplicationEvent.

// Overridden
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    ApplicationContext applicationContext = event.getApplicationContext();
    // only listen to context refresh of "my" applicationContext
    if (this.applicationContext.equals(applicationContext)) {
        CamelContext camelContext = event.getApplicationContext().getBean(CamelContext.class);
        // only add and start Camel if its stopped (initial state)
        if (camelContext.getStatus().isStopped()) {
            LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName());
            for (RoutesBuilder routesBuilder : applicationContext.getBeansOfType(RoutesBuilder.class, configurationProperties.isIncludeNonSingletons(), true).values()) {
                // filter out abstract classes
                boolean abs = Modifier.isAbstract(routesBuilder.getClass().getModifiers());
                if (!abs) {
                    try {
                        LOG.debug("Injecting following route into the CamelContext: {}", routesBuilder);
                        camelContext.addRoutes(routesBuilder);
                    } catch (Exception e) {
                        throw new CamelSpringBootInitializationException(e);
                    }
                }
            }
            try {
                boolean scan = !configurationProperties.getXmlRoutes().equals("false");
                if (scan) {
                    loadXmlRoutes(applicationContext, camelContext, configurationProperties.getXmlRoutes());
                }
                boolean scanRests = !configurationProperties.getXmlRests().equals("false");
                if (scanRests) {
                    loadXmlRests(applicationContext, camelContext, configurationProperties.getXmlRests());
                }
                for (CamelContextConfiguration camelContextConfiguration : camelContextConfigurations) {
                    LOG.debug("CamelContextConfiguration found. Invoking beforeApplicationStart: {}", camelContextConfiguration);
                    camelContextConfiguration.beforeApplicationStart(camelContext);
                }
                if (configurationProperties.isMainRunController()) {
                    CamelMainRunController controller = new CamelMainRunController(applicationContext, camelContext);
                    if (configurationProperties.getDurationMaxMessages() > 0 || configurationProperties.getDurationMaxIdleSeconds() > 0) {
                        if (configurationProperties.getDurationMaxMessages() > 0) {
                            LOG.info("CamelSpringBoot will terminate after processing {} messages", configurationProperties.getDurationMaxMessages());
                        }
                        if (configurationProperties.getDurationMaxIdleSeconds() > 0) {
                            LOG.info("CamelSpringBoot will terminate after being idle for more {} seconds", configurationProperties.getDurationMaxIdleSeconds());
                        }
                        // register lifecycle so we can trigger to shutdown the JVM when maximum number of messages has been processed
                        EventNotifier notifier = new MainDurationEventNotifier(camelContext, configurationProperties.getDurationMaxMessages(), configurationProperties.getDurationMaxIdleSeconds(), controller.getCompleted(), controller.getLatch(), true);
                        // register our event notifier
                        ServiceHelper.startService(notifier);
                        camelContext.getManagementStrategy().addEventNotifier(notifier);
                    }
                    if (configurationProperties.getDurationMaxSeconds() > 0) {
                        LOG.info("CamelSpringBoot will terminate after {} seconds", configurationProperties.getDurationMaxSeconds());
                        terminateMainControllerAfter(camelContext, configurationProperties.getDurationMaxSeconds(), controller.getCompleted(), controller.getLatch());
                    }
                    // controller will start Camel
                    LOG.info("Starting CamelMainRunController to ensure the main thread keeps running");
                    controller.start();
                } else {
                    if (applicationContext instanceof ConfigurableApplicationContext) {
                        ConfigurableApplicationContext cac = (ConfigurableApplicationContext) applicationContext;
                        if (configurationProperties.getDurationMaxSeconds() > 0) {
                            LOG.info("CamelSpringBoot will terminate after {} seconds", configurationProperties.getDurationMaxSeconds());
                            terminateApplicationContext(cac, camelContext, configurationProperties.getDurationMaxSeconds());
                        }
                        if (configurationProperties.getDurationMaxMessages() > 0 || configurationProperties.getDurationMaxIdleSeconds() > 0) {
                            if (configurationProperties.getDurationMaxMessages() > 0) {
                                LOG.info("CamelSpringBoot will terminate after processing {} messages", configurationProperties.getDurationMaxMessages());
                            }
                            if (configurationProperties.getDurationMaxIdleSeconds() > 0) {
                                LOG.info("CamelSpringBoot will terminate after being idle for more {} seconds", configurationProperties.getDurationMaxIdleSeconds());
                            }
                            // needed by MainDurationEventNotifier to signal when we have processed the max messages
                            final AtomicBoolean completed = new AtomicBoolean();
                            final CountDownLatch latch = new CountDownLatch(1);
                            // register lifecycle so we can trigger to shutdown the JVM when maximum number of messages has been processed
                            EventNotifier notifier = new MainDurationEventNotifier(camelContext, configurationProperties.getDurationMaxMessages(), configurationProperties.getDurationMaxIdleSeconds(), completed, latch, false);
                            // register our event notifier
                            ServiceHelper.startService(notifier);
                            camelContext.getManagementStrategy().addEventNotifier(notifier);
                            terminateApplicationContext(cac, camelContext, latch);
                        }
                    }
                    // start camel manually
                    maybeStart(camelContext);
                }
                for (CamelContextConfiguration camelContextConfiguration : camelContextConfigurations) {
                    LOG.debug("CamelContextConfiguration found. Invoking afterApplicationStart: {}", camelContextConfiguration);
                    camelContextConfiguration.afterApplicationStart(camelContext);
                }
            } catch (Exception e) {
                throw new CamelSpringBootInitializationException(e);
            }
        } else {
            LOG.debug("Camel already started, not adding routes.");
        }
    } else {
        LOG.debug("Ignore ContextRefreshedEvent: {}", event);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) CountDownLatch(java.util.concurrent.CountDownLatch) MainDurationEventNotifier(org.apache.camel.main.MainDurationEventNotifier) FileNotFoundException(java.io.FileNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MainDurationEventNotifier(org.apache.camel.main.MainDurationEventNotifier) EventNotifier(org.apache.camel.spi.EventNotifier) RoutesBuilder(org.apache.camel.RoutesBuilder)

Example 17 with EventNotifier

use of org.apache.camel.spi.EventNotifier in project camel by apache.

the class CamelAutoConfiguration method afterPropertiesSet.

/**
     * Performs additional configuration to lookup beans of Camel types to configure
     * advanced configurations.
     * <p/>
     * Similar code in camel-core-xml module in class org.apache.camel.core.xml.AbstractCamelContextFactoryBean.
     */
void afterPropertiesSet(ApplicationContext applicationContext, CamelContext camelContext) {
    Tracer tracer = getSingleBeanOfType(applicationContext, Tracer.class);
    if (tracer != null) {
        // use formatter if there is a TraceFormatter bean defined
        TraceFormatter formatter = getSingleBeanOfType(applicationContext, TraceFormatter.class);
        if (formatter != null) {
            tracer.setFormatter(formatter);
        }
        LOG.info("Using custom Tracer: {}", tracer);
        camelContext.addInterceptStrategy(tracer);
    }
    BacklogTracer backlogTracer = getSingleBeanOfType(applicationContext, BacklogTracer.class);
    if (backlogTracer != null) {
        LOG.info("Using custom BacklogTracer: {}", backlogTracer);
        camelContext.addInterceptStrategy(backlogTracer);
    }
    HandleFault handleFault = getSingleBeanOfType(applicationContext, HandleFault.class);
    if (handleFault != null) {
        LOG.info("Using custom HandleFault: {}", handleFault);
        camelContext.addInterceptStrategy(handleFault);
    }
    InflightRepository inflightRepository = getSingleBeanOfType(applicationContext, InflightRepository.class);
    if (inflightRepository != null) {
        LOG.info("Using custom InflightRepository: {}", inflightRepository);
        camelContext.setInflightRepository(inflightRepository);
    }
    AsyncProcessorAwaitManager asyncProcessorAwaitManager = getSingleBeanOfType(applicationContext, AsyncProcessorAwaitManager.class);
    if (asyncProcessorAwaitManager != null) {
        LOG.info("Using custom AsyncProcessorAwaitManager: {}", asyncProcessorAwaitManager);
        camelContext.setAsyncProcessorAwaitManager(asyncProcessorAwaitManager);
    }
    ManagementStrategy managementStrategy = getSingleBeanOfType(applicationContext, ManagementStrategy.class);
    if (managementStrategy != null) {
        LOG.info("Using custom ManagementStrategy: {}", managementStrategy);
        camelContext.setManagementStrategy(managementStrategy);
    }
    ManagementNamingStrategy managementNamingStrategy = getSingleBeanOfType(applicationContext, ManagementNamingStrategy.class);
    if (managementNamingStrategy != null) {
        LOG.info("Using custom ManagementNamingStrategy: {}", managementNamingStrategy);
        camelContext.getManagementStrategy().setManagementNamingStrategy(managementNamingStrategy);
    }
    EventFactory eventFactory = getSingleBeanOfType(applicationContext, EventFactory.class);
    if (eventFactory != null) {
        LOG.info("Using custom EventFactory: {}", eventFactory);
        camelContext.getManagementStrategy().setEventFactory(eventFactory);
    }
    UnitOfWorkFactory unitOfWorkFactory = getSingleBeanOfType(applicationContext, UnitOfWorkFactory.class);
    if (unitOfWorkFactory != null) {
        LOG.info("Using custom UnitOfWorkFactory: {}", unitOfWorkFactory);
        camelContext.setUnitOfWorkFactory(unitOfWorkFactory);
    }
    RuntimeEndpointRegistry runtimeEndpointRegistry = getSingleBeanOfType(applicationContext, RuntimeEndpointRegistry.class);
    if (runtimeEndpointRegistry != null) {
        LOG.info("Using custom RuntimeEndpointRegistry: {}", runtimeEndpointRegistry);
        camelContext.setRuntimeEndpointRegistry(runtimeEndpointRegistry);
    }
    // custom type converters defined as <bean>s
    Map<String, TypeConverters> typeConverters = applicationContext.getBeansOfType(TypeConverters.class);
    if (typeConverters != null && !typeConverters.isEmpty()) {
        for (Map.Entry<String, TypeConverters> entry : typeConverters.entrySet()) {
            TypeConverters converter = entry.getValue();
            LOG.info("Adding custom TypeConverters with id: {} and implementation: {}", entry.getKey(), converter);
            camelContext.getTypeConverterRegistry().addTypeConverters(converter);
        }
    }
    // set the event notifier strategies if defined
    Map<String, EventNotifier> eventNotifiers = applicationContext.getBeansOfType(EventNotifier.class);
    if (eventNotifiers != null && !eventNotifiers.isEmpty()) {
        for (Map.Entry<String, EventNotifier> entry : eventNotifiers.entrySet()) {
            EventNotifier notifier = entry.getValue();
            // do not add if already added, for instance a tracer that is also an InterceptStrategy class
            if (!camelContext.getManagementStrategy().getEventNotifiers().contains(notifier)) {
                LOG.info("Using custom EventNotifier with id: {} and implementation: {}", entry.getKey(), notifier);
                camelContext.getManagementStrategy().addEventNotifier(notifier);
            }
        }
    }
    // set endpoint strategies if defined
    Map<String, EndpointStrategy> endpointStrategies = applicationContext.getBeansOfType(EndpointStrategy.class);
    if (endpointStrategies != null && !endpointStrategies.isEmpty()) {
        for (Map.Entry<String, EndpointStrategy> entry : endpointStrategies.entrySet()) {
            EndpointStrategy strategy = entry.getValue();
            LOG.info("Using custom EndpointStrategy with id: {} and implementation: {}", entry.getKey(), strategy);
            camelContext.addRegisterEndpointCallback(strategy);
        }
    }
    // shutdown
    ShutdownStrategy shutdownStrategy = getSingleBeanOfType(applicationContext, ShutdownStrategy.class);
    if (shutdownStrategy != null) {
        LOG.info("Using custom ShutdownStrategy: " + shutdownStrategy);
        camelContext.setShutdownStrategy(shutdownStrategy);
    }
    // add global interceptors
    Map<String, InterceptStrategy> interceptStrategies = applicationContext.getBeansOfType(InterceptStrategy.class);
    if (interceptStrategies != null && !interceptStrategies.isEmpty()) {
        for (Map.Entry<String, InterceptStrategy> entry : interceptStrategies.entrySet()) {
            InterceptStrategy strategy = entry.getValue();
            // do not add if already added, for instance a tracer that is also an InterceptStrategy class
            if (!camelContext.getInterceptStrategies().contains(strategy)) {
                LOG.info("Using custom InterceptStrategy with id: {} and implementation: {}", entry.getKey(), strategy);
                camelContext.addInterceptStrategy(strategy);
            }
        }
    }
    // set the lifecycle strategy if defined
    Map<String, LifecycleStrategy> lifecycleStrategies = applicationContext.getBeansOfType(LifecycleStrategy.class);
    if (lifecycleStrategies != null && !lifecycleStrategies.isEmpty()) {
        for (Map.Entry<String, LifecycleStrategy> entry : lifecycleStrategies.entrySet()) {
            LifecycleStrategy strategy = entry.getValue();
            // do not add if already added, for instance a tracer that is also an InterceptStrategy class
            if (!camelContext.getLifecycleStrategies().contains(strategy)) {
                LOG.info("Using custom LifecycleStrategy with id: {} and implementation: {}", entry.getKey(), strategy);
                camelContext.addLifecycleStrategy(strategy);
            }
        }
    }
    // add route policy factories
    Map<String, RoutePolicyFactory> routePolicyFactories = applicationContext.getBeansOfType(RoutePolicyFactory.class);
    if (routePolicyFactories != null && !routePolicyFactories.isEmpty()) {
        for (Map.Entry<String, RoutePolicyFactory> entry : routePolicyFactories.entrySet()) {
            RoutePolicyFactory factory = entry.getValue();
            LOG.info("Using custom RoutePolicyFactory with id: {} and implementation: {}", entry.getKey(), factory);
            camelContext.addRoutePolicyFactory(factory);
        }
    }
    // set the default thread pool profile if defined
    initThreadPoolProfiles(applicationContext, camelContext);
}
Also used : InflightRepository(org.apache.camel.spi.InflightRepository) UnitOfWorkFactory(org.apache.camel.spi.UnitOfWorkFactory) TypeConverters(org.apache.camel.TypeConverters) EndpointStrategy(org.apache.camel.spi.EndpointStrategy) EventNotifier(org.apache.camel.spi.EventNotifier) RoutePolicyFactory(org.apache.camel.spi.RoutePolicyFactory) TraceFormatter(org.apache.camel.processor.interceptor.TraceFormatter) DefaultTraceFormatter(org.apache.camel.processor.interceptor.DefaultTraceFormatter) BacklogTracer(org.apache.camel.processor.interceptor.BacklogTracer) ManagementStrategy(org.apache.camel.spi.ManagementStrategy) ShutdownStrategy(org.apache.camel.spi.ShutdownStrategy) Tracer(org.apache.camel.processor.interceptor.Tracer) BacklogTracer(org.apache.camel.processor.interceptor.BacklogTracer) EventFactory(org.apache.camel.spi.EventFactory) AsyncProcessorAwaitManager(org.apache.camel.spi.AsyncProcessorAwaitManager) InterceptStrategy(org.apache.camel.spi.InterceptStrategy) ManagementNamingStrategy(org.apache.camel.spi.ManagementNamingStrategy) LifecycleStrategy(org.apache.camel.spi.LifecycleStrategy) RuntimeEndpointRegistry(org.apache.camel.spi.RuntimeEndpointRegistry) HandleFault(org.apache.camel.processor.interceptor.HandleFault) Map(java.util.Map)

Example 18 with EventNotifier

use of org.apache.camel.spi.EventNotifier in project camel by apache.

the class DefaultManagementLifecycleStrategy method getManagedObjectForService.

@SuppressWarnings("unchecked")
private Object getManagedObjectForService(CamelContext context, Service service, Route route) {
    // skip channel, UoW and dont double wrap instrumentation
    if (service instanceof Channel || service instanceof UnitOfWork || service instanceof InstrumentationProcessor) {
        return null;
    }
    // skip non managed services
    if (service instanceof NonManagedService) {
        return null;
    }
    Object answer = null;
    if (service instanceof ManagementAware) {
        return ((ManagementAware<Service>) service).getManagedObject(service);
    } else if (service instanceof Tracer) {
        // special for tracer
        Tracer tracer = (Tracer) service;
        ManagedTracer mt = managedTracers.get(tracer);
        if (mt == null) {
            mt = new ManagedTracer(context, tracer);
            mt.init(getManagementStrategy());
            managedTracers.put(tracer, mt);
        }
        return mt;
    } else if (service instanceof BacklogTracer) {
        // special for backlog tracer
        BacklogTracer backlogTracer = (BacklogTracer) service;
        ManagedBacklogTracer mt = managedBacklogTracers.get(backlogTracer);
        if (mt == null) {
            mt = new ManagedBacklogTracer(context, backlogTracer);
            mt.init(getManagementStrategy());
            managedBacklogTracers.put(backlogTracer, mt);
        }
        return mt;
    } else if (service instanceof BacklogDebugger) {
        // special for backlog debugger
        BacklogDebugger backlogDebugger = (BacklogDebugger) service;
        ManagedBacklogDebugger md = managedBacklogDebuggers.get(backlogDebugger);
        if (md == null) {
            md = new ManagedBacklogDebugger(context, backlogDebugger);
            md.init(getManagementStrategy());
            managedBacklogDebuggers.put(backlogDebugger, md);
        }
        return md;
    } else if (service instanceof DataFormat) {
        answer = getManagementObjectStrategy().getManagedObjectForDataFormat(context, (DataFormat) service);
    } else if (service instanceof Producer) {
        answer = getManagementObjectStrategy().getManagedObjectForProducer(context, (Producer) service);
    } else if (service instanceof Consumer) {
        answer = getManagementObjectStrategy().getManagedObjectForConsumer(context, (Consumer) service);
    } else if (service instanceof Processor) {
        // special for processors as we need to do some extra work
        return getManagedObjectForProcessor(context, (Processor) service, route);
    } else if (service instanceof ThrottlingInflightRoutePolicy) {
        answer = new ManagedThrottlingInflightRoutePolicy(context, (ThrottlingInflightRoutePolicy) service);
    } else if (service instanceof ThrottlingExceptionRoutePolicy) {
        answer = new ManagedThrottlingExceptionRoutePolicy(context, (ThrottlingExceptionRoutePolicy) service);
    } else if (service instanceof ConsumerCache) {
        answer = new ManagedConsumerCache(context, (ConsumerCache) service);
    } else if (service instanceof ProducerCache) {
        answer = new ManagedProducerCache(context, (ProducerCache) service);
    } else if (service instanceof DefaultEndpointRegistry) {
        answer = new ManagedEndpointRegistry(context, (DefaultEndpointRegistry) service);
    } else if (service instanceof TypeConverterRegistry) {
        answer = new ManagedTypeConverterRegistry(context, (TypeConverterRegistry) service);
    } else if (service instanceof RestRegistry) {
        answer = new ManagedRestRegistry(context, (RestRegistry) service);
    } else if (service instanceof InflightRepository) {
        answer = new ManagedInflightRepository(context, (InflightRepository) service);
    } else if (service instanceof AsyncProcessorAwaitManager) {
        answer = new ManagedAsyncProcessorAwaitManager(context, (AsyncProcessorAwaitManager) service);
    } else if (service instanceof RuntimeEndpointRegistry) {
        answer = new ManagedRuntimeEndpointRegistry(context, (RuntimeEndpointRegistry) service);
    } else if (service instanceof StreamCachingStrategy) {
        answer = new ManagedStreamCachingStrategy(context, (StreamCachingStrategy) service);
    } else if (service instanceof EventNotifier) {
        answer = getManagementObjectStrategy().getManagedObjectForEventNotifier(context, (EventNotifier) service);
    } else if (service instanceof TransformerRegistry) {
        answer = new ManagedTransformerRegistry(context, (TransformerRegistry) service);
    } else if (service instanceof ValidatorRegistry) {
        answer = new ManagedValidatorRegistry(context, (ValidatorRegistry) service);
    } else if (service instanceof RuntimeCamelCatalog) {
        answer = new ManagedRuntimeCamelCatalog(context, (RuntimeCamelCatalog) service);
    } else if (service != null) {
        // fallback as generic service
        answer = getManagementObjectStrategy().getManagedObjectForService(context, service);
    }
    if (answer != null && answer instanceof ManagedService) {
        ManagedService ms = (ManagedService) answer;
        ms.setRoute(route);
        ms.init(getManagementStrategy());
    }
    return answer;
}
Also used : ManagedAsyncProcessorAwaitManager(org.apache.camel.management.mbean.ManagedAsyncProcessorAwaitManager) UnitOfWork(org.apache.camel.spi.UnitOfWork) CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) Processor(org.apache.camel.Processor) InflightRepository(org.apache.camel.spi.InflightRepository) ManagedInflightRepository(org.apache.camel.management.mbean.ManagedInflightRepository) ManagedTracer(org.apache.camel.management.mbean.ManagedTracer) ManagedRestRegistry(org.apache.camel.management.mbean.ManagedRestRegistry) ManagedThrottlingInflightRoutePolicy(org.apache.camel.management.mbean.ManagedThrottlingInflightRoutePolicy) RestRegistry(org.apache.camel.spi.RestRegistry) ManagedRestRegistry(org.apache.camel.management.mbean.ManagedRestRegistry) ManagedValidatorRegistry(org.apache.camel.management.mbean.ManagedValidatorRegistry) DefaultValidatorRegistry(org.apache.camel.impl.DefaultValidatorRegistry) ValidatorRegistry(org.apache.camel.spi.ValidatorRegistry) ManagedRuntimeCamelCatalog(org.apache.camel.management.mbean.ManagedRuntimeCamelCatalog) DefaultEndpointRegistry(org.apache.camel.impl.DefaultEndpointRegistry) ManagedConsumerCache(org.apache.camel.management.mbean.ManagedConsumerCache) ManagedProducerCache(org.apache.camel.management.mbean.ManagedProducerCache) ProducerCache(org.apache.camel.impl.ProducerCache) ManagedStreamCachingStrategy(org.apache.camel.management.mbean.ManagedStreamCachingStrategy) ThrottlingInflightRoutePolicy(org.apache.camel.impl.ThrottlingInflightRoutePolicy) ManagedThrottlingInflightRoutePolicy(org.apache.camel.management.mbean.ManagedThrottlingInflightRoutePolicy) ManagedEndpointRegistry(org.apache.camel.management.mbean.ManagedEndpointRegistry) Consumer(org.apache.camel.Consumer) ManagedTypeConverterRegistry(org.apache.camel.management.mbean.ManagedTypeConverterRegistry) TypeConverterRegistry(org.apache.camel.spi.TypeConverterRegistry) EventNotifier(org.apache.camel.spi.EventNotifier) DataFormat(org.apache.camel.spi.DataFormat) ManagedThrottlingExceptionRoutePolicy(org.apache.camel.management.mbean.ManagedThrottlingExceptionRoutePolicy) DefaultTransformerRegistry(org.apache.camel.impl.DefaultTransformerRegistry) ManagedTransformerRegistry(org.apache.camel.management.mbean.ManagedTransformerRegistry) TransformerRegistry(org.apache.camel.spi.TransformerRegistry) ManagedService(org.apache.camel.management.mbean.ManagedService) NonManagedService(org.apache.camel.NonManagedService) ManagedBacklogTracer(org.apache.camel.management.mbean.ManagedBacklogTracer) BacklogTracer(org.apache.camel.processor.interceptor.BacklogTracer) ManagedBacklogDebugger(org.apache.camel.management.mbean.ManagedBacklogDebugger) ManagedBacklogTracer(org.apache.camel.management.mbean.ManagedBacklogTracer) Tracer(org.apache.camel.processor.interceptor.Tracer) BacklogTracer(org.apache.camel.processor.interceptor.BacklogTracer) ManagedTracer(org.apache.camel.management.mbean.ManagedTracer) Channel(org.apache.camel.Channel) ManagedAsyncProcessorAwaitManager(org.apache.camel.management.mbean.ManagedAsyncProcessorAwaitManager) AsyncProcessorAwaitManager(org.apache.camel.spi.AsyncProcessorAwaitManager) ManagedRuntimeCamelCatalog(org.apache.camel.management.mbean.ManagedRuntimeCamelCatalog) RuntimeCamelCatalog(org.apache.camel.catalog.RuntimeCamelCatalog) ManagedTypeConverterRegistry(org.apache.camel.management.mbean.ManagedTypeConverterRegistry) Producer(org.apache.camel.Producer) ManagedValidatorRegistry(org.apache.camel.management.mbean.ManagedValidatorRegistry) ManagedRuntimeEndpointRegistry(org.apache.camel.management.mbean.ManagedRuntimeEndpointRegistry) RuntimeEndpointRegistry(org.apache.camel.spi.RuntimeEndpointRegistry) ManagedInflightRepository(org.apache.camel.management.mbean.ManagedInflightRepository) ConsumerCache(org.apache.camel.impl.ConsumerCache) ManagedConsumerCache(org.apache.camel.management.mbean.ManagedConsumerCache) ManagedTransformerRegistry(org.apache.camel.management.mbean.ManagedTransformerRegistry) ManagedProducerCache(org.apache.camel.management.mbean.ManagedProducerCache) ManagementAware(org.apache.camel.spi.ManagementAware) StreamCachingStrategy(org.apache.camel.spi.StreamCachingStrategy) ManagedStreamCachingStrategy(org.apache.camel.management.mbean.ManagedStreamCachingStrategy) NonManagedService(org.apache.camel.NonManagedService) ManagedBacklogDebugger(org.apache.camel.management.mbean.ManagedBacklogDebugger) BacklogDebugger(org.apache.camel.processor.interceptor.BacklogDebugger) ManagedBacklogTracer(org.apache.camel.management.mbean.ManagedBacklogTracer) ManagedRuntimeEndpointRegistry(org.apache.camel.management.mbean.ManagedRuntimeEndpointRegistry) ThrottlingExceptionRoutePolicy(org.apache.camel.impl.ThrottlingExceptionRoutePolicy) ManagedThrottlingExceptionRoutePolicy(org.apache.camel.management.mbean.ManagedThrottlingExceptionRoutePolicy)

Example 19 with EventNotifier

use of org.apache.camel.spi.EventNotifier in project camel by apache.

the class DefaultManagementStrategy method doStartManagementStrategy.

protected void doStartManagementStrategy() throws Exception {
    ObjectHelper.notNull(camelContext, "CamelContext");
    if (eventNotifiers != null) {
        for (EventNotifier notifier : eventNotifiers) {
            // inject CamelContext if the service is aware
            if (notifier instanceof CamelContextAware) {
                CamelContextAware aware = (CamelContextAware) notifier;
                aware.setCamelContext(camelContext);
            }
            ServiceHelper.startService(notifier);
        }
    }
    if (managementAgent != null) {
        ServiceHelper.startService(managementAgent);
        // set the naming strategy using the domain name from the agent
        if (managementNamingStrategy == null) {
            setManagementNamingStrategy(new DefaultManagementNamingStrategy(managementAgent.getMBeanObjectDomainName()));
        }
    }
    if (managementNamingStrategy instanceof CamelContextAware) {
        ((CamelContextAware) managementNamingStrategy).setCamelContext(getCamelContext());
    }
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) EventNotifier(org.apache.camel.spi.EventNotifier)

Example 20 with EventNotifier

use of org.apache.camel.spi.EventNotifier in project camel by apache.

the class EventHelper method notifyCamelContextStartupFailed.

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);
    }
}
Also used : ManagementStrategy(org.apache.camel.spi.ManagementStrategy) EventNotifier(org.apache.camel.spi.EventNotifier) EventFactory(org.apache.camel.spi.EventFactory) EventObject(java.util.EventObject)

Aggregations

EventNotifier (org.apache.camel.spi.EventNotifier)34 ManagementStrategy (org.apache.camel.spi.ManagementStrategy)28 EventFactory (org.apache.camel.spi.EventFactory)27 EventObject (java.util.EventObject)25 LifecycleStrategy (org.apache.camel.spi.LifecycleStrategy)4 BacklogTracer (org.apache.camel.processor.interceptor.BacklogTracer)3 HandleFault (org.apache.camel.processor.interceptor.HandleFault)3 Tracer (org.apache.camel.processor.interceptor.Tracer)3 AsyncProcessorAwaitManager (org.apache.camel.spi.AsyncProcessorAwaitManager)3 InflightRepository (org.apache.camel.spi.InflightRepository)3 RuntimeEndpointRegistry (org.apache.camel.spi.RuntimeEndpointRegistry)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CamelContextAware (org.apache.camel.CamelContextAware)2 Consumer (org.apache.camel.Consumer)2 Service (org.apache.camel.Service)2 StatefulService (org.apache.camel.StatefulService)2 SuspendableService (org.apache.camel.SuspendableService)2