Search in sources :

Example 76 with CamelContextAware

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

the class JohnzonDataFormatAutoConfiguration method configureJohnzonDataFormatFactory.

@Bean(name = "json-johnzon-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JohnzonDataFormat.class)
public DataFormatFactory configureJohnzonDataFormatFactory(final CamelContext camelContext, final JohnzonDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            JohnzonDataFormat dataformat = new JohnzonDataFormat();
            if (CamelContextAware.class.isAssignableFrom(JohnzonDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : JohnzonDataFormat(org.apache.camel.component.johnzon.JohnzonDataFormat) DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 77 with CamelContextAware

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

the class SqlLanguageAutoConfiguration method configureSqlLanguage.

@Bean(name = "sql-language")
@Scope("prototype")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SqlLanguage.class)
public SqlLanguage configureSqlLanguage(CamelContext camelContext, SqlLanguageConfiguration configuration) throws Exception {
    SqlLanguage language = new SqlLanguage();
    if (CamelContextAware.class.isAssignableFrom(SqlLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class.cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), language, parameters);
    return language;
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) SqlLanguage(org.apache.camel.language.sql.SqlLanguage) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 78 with CamelContextAware

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

the class JsonPathLanguageAutoConfiguration method configureJsonPathLanguage.

@Bean(name = "jsonpath-language")
@Scope("prototype")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JsonPathLanguage.class)
public JsonPathLanguage configureJsonPathLanguage(CamelContext camelContext, JsonPathLanguageConfiguration configuration) throws Exception {
    JsonPathLanguage language = new JsonPathLanguage();
    if (CamelContextAware.class.isAssignableFrom(JsonPathLanguage.class)) {
        CamelContextAware contextAware = CamelContextAware.class.cast(language);
        if (contextAware != null) {
            contextAware.setCamelContext(camelContext);
        }
    }
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), language, parameters);
    return language;
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) JsonPathLanguage(org.apache.camel.jsonpath.JsonPathLanguage) Scope(org.springframework.context.annotation.Scope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 79 with CamelContextAware

use of org.apache.camel.CamelContextAware 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 80 with CamelContextAware

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

the class AggregateDefinition method createAggregationStrategy.

private AggregationStrategy createAggregationStrategy(RouteContext routeContext) {
    AggregationStrategy strategy = getAggregationStrategy();
    if (strategy == null && strategyRef != null) {
        Object aggStrategy = routeContext.lookup(strategyRef, Object.class);
        if (aggStrategy instanceof AggregationStrategy) {
            strategy = (AggregationStrategy) aggStrategy;
        } else if (aggStrategy != null) {
            AggregationStrategyBeanAdapter adapter = new AggregationStrategyBeanAdapter(aggStrategy, getAggregationStrategyMethodName());
            if (getStrategyMethodAllowNull() != null) {
                adapter.setAllowNullNewExchange(getStrategyMethodAllowNull());
                adapter.setAllowNullOldExchange(getStrategyMethodAllowNull());
            }
            strategy = adapter;
        } else {
            throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef);
        }
    }
    if (groupExchanges != null && groupExchanges) {
        if (strategy != null || strategyRef != null) {
            throw new IllegalArgumentException("Options groupExchanges and AggregationStrategy cannot be enabled at the same time");
        }
        if (eagerCheckCompletion != null && !eagerCheckCompletion) {
            throw new IllegalArgumentException("Option eagerCheckCompletion cannot be false when groupExchanges has been enabled");
        }
        // set eager check to enabled by default when using grouped exchanges
        setEagerCheckCompletion(true);
        // if grouped exchange is enabled then use special strategy for that
        strategy = new GroupedExchangeAggregationStrategy();
    }
    if (strategy == null) {
        throw new IllegalArgumentException("AggregationStrategy or AggregationStrategyRef must be set on " + this);
    }
    if (strategy instanceof CamelContextAware) {
        ((CamelContextAware) strategy).setCamelContext(routeContext.getCamelContext());
    }
    return strategy;
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) GroupedExchangeAggregationStrategy(org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy) GroupedExchangeAggregationStrategy(org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregationStrategyBeanAdapter(org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)

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