use of org.apache.camel.impl.DefaultCamelContext 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;
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class CamelContextProducer method produce.
@Override
public T produce(CreationalContext<T> ctx) {
T context = super.produce(ctx);
// Do not override the name if it's been already set (in the bean constructor for example)
if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy) {
context.setNameStrategy(nameStrategy(annotated));
}
// Add bean registry and Camel injector
if (context instanceof DefaultCamelContext) {
DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
adapted.setRegistry(new CdiCamelRegistry(manager));
adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
} else {
// Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
}
// Add event notifier if at least one observer is present
Set<Annotation> qualifiers = annotated.getAnnotations().stream().filter(isAnnotationType(Named.class).negate().and(q -> manager.isQualifier(q.annotationType()))).collect(toSet());
qualifiers.add(ANY);
if (qualifiers.size() == 1) {
qualifiers.add(DEFAULT);
}
qualifiers.retainAll(extension.getObserverEvents());
if (!qualifiers.isEmpty()) {
context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));
}
return context;
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class XmlCdiBeanFactory method camelContextBean.
private SyntheticBean<?> camelContextBean(CamelContextFactoryBean factory, URL url) {
Set<Annotation> annotations = new HashSet<>();
annotations.add(ANY);
if (hasId(factory)) {
addAll(annotations, ContextName.Literal.of(factory.getId()), NamedLiteral.of(factory.getId()));
} else {
annotations.add(DEFAULT);
factory.setImplicitId(true);
factory.setId(new CdiCamelContextNameStrategy().getNextName());
}
annotations.add(APPLICATION_SCOPED);
SyntheticAnnotated annotated = new SyntheticAnnotated(DefaultCamelContext.class, manager.createAnnotatedType(DefaultCamelContext.class).getTypeClosure(), annotations);
return new SyntheticBean<>(manager, annotated, DefaultCamelContext.class, environment.camelContextInjectionTarget(new SyntheticInjectionTarget<>(() -> {
DefaultCamelContext context = new DefaultCamelContext();
factory.setContext(context);
factory.setBeanManager(manager);
return context;
}, context -> {
try {
factory.afterPropertiesSet();
} catch (Exception cause) {
throw new CreationException(cause);
}
}), annotated, manager, extension), bean -> "imported Camel context with " + (factory.isImplicitId() ? "implicit " : "") + "id [" + factory.getId() + "] " + "from resource [" + url + "] " + "with qualifiers " + bean.getQualifiers());
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class CassandraAggregationRepositoryTest method setUp.
@Before
public void setUp() throws Exception {
camelContext = new DefaultCamelContext();
if (canTest()) {
cluster = CassandraUnitUtils.cassandraCluster();
session = cluster.connect(CassandraUnitUtils.KEYSPACE);
aggregationRepository = new CassandraAggregationRepository(session);
aggregationRepository.start();
}
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class NamedCassandraAggregationRepositoryTest method setUp.
@Before
public void setUp() throws Exception {
camelContext = new DefaultCamelContext();
if (canTest()) {
cluster = CassandraUnitUtils.cassandraCluster();
session = cluster.connect(CassandraUnitUtils.KEYSPACE);
aggregationRepository = new NamedCassandraAggregationRepository(session, "ID");
aggregationRepository.setTable("NAMED_CAMEL_AGGREGATION");
aggregationRepository.start();
}
}
Aggregations