use of org.apache.camel.Channel in project camel by apache.
the class ContextErrorHandlerTest method testGetTheDefaultErrorHandlerFromContext.
public void testGetTheDefaultErrorHandlerFromContext() throws Exception {
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("seda:a").to("seda:b");
from("direct:c").to("direct:d");
}
};
List<Route> list = getRouteListWithCurrentContext(builder);
assertEquals("Number routes created" + list, 2, list.size());
for (Route route : list) {
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Processor processor = consumerRoute.getProcessor();
Channel channel = unwrapChannel(processor);
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.Channel in project camel by apache.
the class StreamResequencerTest method doTestStreamResequencerType.
protected void doTestStreamResequencerType() throws Exception {
List<Route> list = getRouteList(createRouteBuilder());
assertEquals("Number of routes created: " + list, 1, list.size());
Route route = list.get(0);
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
assertIsInstanceOf(DefaultErrorHandler.class, channel.getErrorHandler());
assertIsInstanceOf(StreamResequencer.class, channel.getNextProcessor());
}
use of org.apache.camel.Channel in project camel by apache.
the class ErrorHandlerTest method testEndpointConfiguration.
public void testEndpointConfiguration() throws Exception {
SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
List<Route> list = context.getRoutes();
assertEquals("Number routes created" + list, 2, list.size());
for (Route route : list) {
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.Channel 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;
}
use of org.apache.camel.Channel in project camel by apache.
the class ProcessorDefinition method createOutputsProcessorImpl.
protected Processor createOutputsProcessorImpl(RouteContext routeContext, Collection<ProcessorDefinition<?>> outputs) throws Exception {
List<Processor> list = new ArrayList<Processor>();
for (ProcessorDefinition<?> output : outputs) {
// allow any custom logic before we create the processor
output.preCreateProcessor();
// resolve properties before we create the processor
ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), output);
// resolve constant fields (eg Exchange.FILE_NAME)
ProcessorDefinitionHelper.resolveKnownConstantFields(output);
// also resolve properties and constant fields on embedded expressions
ProcessorDefinition<?> me = (ProcessorDefinition<?>) output;
if (me instanceof ExpressionNode) {
ExpressionNode exp = (ExpressionNode) me;
ExpressionDefinition expressionDefinition = exp.getExpression();
if (expressionDefinition != null) {
// resolve properties before we create the processor
ProcessorDefinitionHelper.resolvePropertyPlaceholders(routeContext.getCamelContext(), expressionDefinition);
// resolve constant fields (eg Exchange.FILE_NAME)
ProcessorDefinitionHelper.resolveKnownConstantFields(expressionDefinition);
}
}
Processor processor = createProcessor(routeContext, output);
// inject id
if (processor instanceof IdAware) {
String id = output.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
((IdAware) processor).setId(id);
}
if (output instanceof Channel && processor == null) {
continue;
}
Processor channel = wrapChannel(routeContext, processor, output);
list.add(channel);
}
// if more than one output wrap than in a composite processor else just keep it as is
Processor processor = null;
if (!list.isEmpty()) {
if (list.size() == 1) {
processor = list.get(0);
} else {
processor = createCompositeProcessor(routeContext, list);
}
}
return processor;
}
Aggregations