Search in sources :

Example 1 with OsgiCamelContextPublisher

use of org.apache.camel.core.osgi.OsgiCamelContextPublisher in project camel by apache.

the class CamelContextOsgiProducer method produce.

@Override
public T produce(CreationalContext<T> ctx) {
    T context = super.produce(ctx);
    // Register the context in the OSGi registry
    BundleContext bundle = BundleContextUtils.getBundleContext(getClass());
    context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle));
    if (!(context instanceof DefaultCamelContext)) {
        // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface
        throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }
    DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
    adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle));
    CamelContextNameStrategy strategy = context.getNameStrategy();
    OsgiCamelContextHelper.osgiUpdate(adapted, bundle);
    // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely
    if (!(strategy instanceof DefaultCamelContextNameStrategy)) {
        context.setNameStrategy(strategy);
    }
    return context;
}
Also used : InjectionException(javax.enterprise.inject.InjectionException) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) OsgiCamelContextPublisher(org.apache.camel.core.osgi.OsgiCamelContextPublisher) CamelContextNameStrategy(org.apache.camel.spi.CamelContextNameStrategy) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BundleContext(org.osgi.framework.BundleContext)

Example 2 with OsgiCamelContextPublisher

use of org.apache.camel.core.osgi.OsgiCamelContextPublisher in project camel by apache.

the class CamelContextFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    getContext().getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext));
    try {
        getClass().getClassLoader().loadClass("org.osgi.service.event.EventAdmin");
        getContext().getManagementStrategy().addEventNotifier(new OsgiEventAdminNotifier(bundleContext));
    } catch (Throwable t) {
        // Ignore, if the EventAdmin package is not available, just don't use it
        LOG.debug("EventAdmin package is not available, just don't use it");
    }
}
Also used : OsgiEventAdminNotifier(org.apache.camel.core.osgi.OsgiEventAdminNotifier) OsgiCamelContextPublisher(org.apache.camel.core.osgi.OsgiCamelContextPublisher)

Example 3 with OsgiCamelContextPublisher

use of org.apache.camel.core.osgi.OsgiCamelContextPublisher in project camel by apache.

the class BlueprintCamelContext method maybeStart.

private void maybeStart() throws Exception {
    LOG.trace("maybeStart: {}", this);
    if (!routeDefinitionValid.get()) {
        LOG.trace("maybeStart: {} is skipping since CamelRoute definition is not correct.", this);
        return;
    }
    // allow to register the BluerintCamelContext eager in the OSGi Service Registry, which ex is needed
    // for unit testing with camel-test-blueprint
    boolean eager = "true".equalsIgnoreCase(System.getProperty("registerBlueprintCamelContextEager"));
    if (eager) {
        for (EventNotifier notifier : getManagementStrategy().getEventNotifiers()) {
            if (notifier instanceof OsgiCamelContextPublisher) {
                OsgiCamelContextPublisher publisher = (OsgiCamelContextPublisher) notifier;
                publisher.registerCamelContext(this);
                break;
            }
        }
    }
    // for example from unit testing we want to start Camel later and not
    // when blueprint loading the bundle
    boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
    if (skip) {
        LOG.trace("maybeStart: {} is skipping as System property skipStartingCamelContext is set", this);
        return;
    }
    if (!isStarted() && !isStarting()) {
        LOG.debug("Starting {}", this);
        start();
    } else {
        // ignore as Camel is already started
        LOG.trace("Ignoring maybeStart() as {} is already started", this);
    }
}
Also used : OsgiCamelContextPublisher(org.apache.camel.core.osgi.OsgiCamelContextPublisher) EventNotifier(org.apache.camel.spi.EventNotifier)

Example 4 with OsgiCamelContextPublisher

use of org.apache.camel.core.osgi.OsgiCamelContextPublisher in project camel by apache.

the class CamelContextFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    // setup the application context classloader with the bundle delegating classloader
    ClassLoader cl = new BundleDelegatingClassLoader(bundleContext.getBundle());
    LOG.debug("Set the application context classloader to: {}", cl);
    getContext().setApplicationContextClassLoader(cl);
    osgiCamelContextPublisher = new OsgiCamelContextPublisher(bundleContext);
    osgiCamelContextPublisher.start();
    getContext().getManagementStrategy().addEventNotifier(osgiCamelContextPublisher);
    try {
        getClass().getClassLoader().loadClass("org.osgi.service.event.EventAdmin");
        getContext().getManagementStrategy().addEventNotifier(new OsgiEventAdminNotifier(bundleContext));
    } catch (Throwable t) {
        // Ignore, if the EventAdmin package is not available, just don't use it
        LOG.debug("EventAdmin package is not available, just don't use it");
    }
    // ensure routes is setup
    setupRoutes();
}
Also used : OsgiEventAdminNotifier(org.apache.camel.core.osgi.OsgiEventAdminNotifier) OsgiCamelContextPublisher(org.apache.camel.core.osgi.OsgiCamelContextPublisher) BundleDelegatingClassLoader(org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader) BundleDelegatingClassLoader(org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader)

Example 5 with OsgiCamelContextPublisher

use of org.apache.camel.core.osgi.OsgiCamelContextPublisher in project aries by apache.

the class CamelContextFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    BundleContext bundleContext = getBundleContext();
    getContext().getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext));
    try {
        getClass().getClassLoader().loadClass("org.osgi.service.event.EventAdmin");
        getContext().getManagementStrategy().addEventNotifier(new OsgiEventAdminNotifier(bundleContext));
    } catch (Throwable t) {
        // Ignore, if the EventAdmin package is not available, just don't use it
        LOG.debug("EventAdmin package is not available, just don't use it");
    }
}
Also used : OsgiEventAdminNotifier(org.apache.camel.core.osgi.OsgiEventAdminNotifier) OsgiCamelContextPublisher(org.apache.camel.core.osgi.OsgiCamelContextPublisher) BundleContext(org.osgi.framework.BundleContext)

Aggregations

OsgiCamelContextPublisher (org.apache.camel.core.osgi.OsgiCamelContextPublisher)5 OsgiEventAdminNotifier (org.apache.camel.core.osgi.OsgiEventAdminNotifier)3 BundleContext (org.osgi.framework.BundleContext)2 InjectionException (javax.enterprise.inject.InjectionException)1 BundleDelegatingClassLoader (org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultCamelContextNameStrategy (org.apache.camel.impl.DefaultCamelContextNameStrategy)1 CamelContextNameStrategy (org.apache.camel.spi.CamelContextNameStrategy)1 EventNotifier (org.apache.camel.spi.EventNotifier)1