Search in sources :

Example 81 with CamelContextAware

use of org.apache.camel.CamelContextAware in project camel by apache.

the class DefaultCamelContext method doAddService.

private void doAddService(Object object, boolean stopOnShutdown, boolean forceStart) throws Exception {
    // inject CamelContext
    if (object instanceof CamelContextAware) {
        CamelContextAware aware = (CamelContextAware) object;
        aware.setCamelContext(this);
    }
    if (object instanceof Service) {
        Service service = (Service) object;
        for (LifecycleStrategy strategy : lifecycleStrategies) {
            if (service instanceof Endpoint) {
                // use specialized endpoint add
                strategy.onEndpointAdd((Endpoint) service);
            } else {
                strategy.onServiceAdd(this, service, null);
            }
        }
        if (!forceStart) {
            // now start the service (and defer starting if CamelContext is starting up itself)
            deferStartService(object, stopOnShutdown);
        } else {
            // only add to services to close if its a singleton
            // otherwise we could for example end up with a lot of prototype scope endpoints
            // assume singleton by default
            boolean singleton = true;
            if (object instanceof IsSingleton) {
                singleton = ((IsSingleton) service).isSingleton();
            }
            // do not add endpoints as they have their own list
            if (singleton && !(service instanceof Endpoint)) {
                // only add to list of services to stop if its not already there
                if (stopOnShutdown && !hasService(service)) {
                    servicesToStop.add(service);
                }
            }
            ServiceHelper.startService(service);
        }
    }
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) IsSingleton(org.apache.camel.IsSingleton) Endpoint(org.apache.camel.Endpoint) LifecycleStrategy(org.apache.camel.spi.LifecycleStrategy) Service(org.apache.camel.Service) StatefulService(org.apache.camel.StatefulService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SuspendableService(org.apache.camel.SuspendableService)

Example 82 with CamelContextAware

use of org.apache.camel.CamelContextAware in project camel by apache.

the class BaseTypeConverterRegistry method addFallbackTypeConverter.

@Override
public void addFallbackTypeConverter(TypeConverter typeConverter, boolean canPromote) {
    log.trace("Adding fallback type converter: {} which can promote: {}", typeConverter, canPromote);
    // add in top of fallback as the toString() fallback will nearly always be able to convert
    // the last one which is add to the FallbackTypeConverter will be called at the first place
    fallbackConverters.add(0, new FallbackTypeConverter(typeConverter, canPromote));
    if (typeConverter instanceof TypeConverterAware) {
        TypeConverterAware typeConverterAware = (TypeConverterAware) typeConverter;
        typeConverterAware.setTypeConverter(this);
    }
    if (typeConverter instanceof CamelContextAware) {
        CamelContextAware camelContextAware = (CamelContextAware) typeConverter;
        if (camelContext != null) {
            camelContextAware.setCamelContext(camelContext);
        }
    }
}
Also used : TypeConverterAware(org.apache.camel.spi.TypeConverterAware) CamelContextAware(org.apache.camel.CamelContextAware)

Aggregations

CamelContextAware (org.apache.camel.CamelContextAware)82 HashMap (java.util.HashMap)70 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)69 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)69 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)69 Bean (org.springframework.context.annotation.Bean)69 RuntimeCamelException (org.apache.camel.RuntimeCamelException)47 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)45 Scope (org.springframework.context.annotation.Scope)24 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 CamelContext (org.apache.camel.CamelContext)3 Service (org.apache.camel.Service)3 StatefulService (org.apache.camel.StatefulService)3 SuspendableService (org.apache.camel.SuspendableService)3 IOException (java.io.IOException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 FailedToStartRouteException (org.apache.camel.FailedToStartRouteException)2 IsSingleton (org.apache.camel.IsSingleton)2 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)2