protected Processor createErrorHandler( RouteContext routeContext, Exchange exchange, Processor processor) { Processor answer; boolean tryBlock = exchange.getProperty(Exchange.TRY_ROUTE_BLOCK, false, boolean.class); // do not wrap in error handler if we are inside a try block if (!tryBlock && routeContext != null) { // wrap the producer in error handler so we have fine grained error handling on // the output side instead of the input side // this is needed to support redelivery on that output alone and not doing redelivery // for the entire multicast block again which will start from scratch again // create key for cache final PreparedErrorHandler key = new PreparedErrorHandler(routeContext, processor); // lookup cached first to reuse and preserve memory answer = errorHandlers.get(key); if (answer != null) { LOG.trace("Using existing error handler for: {}", processor); return answer; } LOG.trace("Creating error handler for: {}", processor); ErrorHandlerFactory builder = routeContext.getRoute().getErrorHandlerBuilder(); // create error handler (create error handler directly to keep it light weight, // instead of using ProcessorDefinition.wrapInErrorHandler) try { processor = builder.createErrorHandler(routeContext, processor); // and wrap in unit of work processor so the copy exchange also can run under UoW answer = createUnitOfWorkProcessor(routeContext, processor, exchange); boolean child = exchange.getProperty(Exchange.PARENT_UNIT_OF_WORK, UnitOfWork.class) != null; // must start the error handler ServiceHelper.startServices(answer); // here we don't cache the child unit of work if (!child) { // add to cache errorHandlers.putIfAbsent(key, answer); } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } } else { // and wrap in unit of work processor so the copy exchange also can run under UoW answer = createUnitOfWorkProcessor(routeContext, processor, exchange); } return answer; }
@Override protected void doStart() throws Exception { ServiceHelper.startServices(output, outputAsync, deadLetter); // use a shared scheduler if (executorService == null || executorService.isShutdown()) { // camel context will shutdown the executor when it shutdown so no need to shut it down when // stopping if (executorServiceRef != null) { executorService = camelContext .getExecutorServiceStrategy() .lookupScheduled(this, "ErrorHandlerRedeliveryTask", executorServiceRef); if (executorService == null) { throw new IllegalArgumentException( "ExecutorServiceRef " + executorServiceRef + " not found in registry."); } } else { executorService = camelContext .getExecutorServiceStrategy() .newScheduledThreadPool(this, "ErrorHandlerRedeliveryTask"); } } // determine if redeliver is enabled or not redeliveryEnabled = determineIfRedeliveryIsEnabled(); if (log.isDebugEnabled()) { log.debug("Redelivery enabled: {} on error handler: {}", redeliveryEnabled, this); } }
@Override @Before protected void setUp() throws Exception { super.setUp(); context2 = new DefaultCamelContext(); template2 = context2.createProducerTemplate(); ServiceHelper.startServices(template2, context2); // add routes after CamelContext has been started RouteBuilder routeBuilder = createRouteBuilderForSecondContext(); if (routeBuilder != null) { context2.addRoutes(routeBuilder); } }
protected void doStart() throws Exception { if (consumerCache == null) { // create consumer cache if we use dynamic expressions for computing the endpoints to poll if (cacheSize < 0) { consumerCache = new EmptyConsumerCache(this, camelContext); LOG.debug("PollEnrich {} is not using ConsumerCache", this); } else if (cacheSize == 0) { consumerCache = new ConsumerCache(this, camelContext); LOG.debug("PollEnrich {} using ConsumerCache with default cache size", this); } else { consumerCache = new ConsumerCache(this, camelContext, cacheSize); LOG.debug("PollEnrich {} using ConsumerCache with cacheSize={}", this, cacheSize); } } ServiceHelper.startServices(consumerCache, aggregationStrategy); }
@Override protected void doStart() throws Exception { // inject CamelContext before starting if (jsonMarshal instanceof CamelContextAware) { ((CamelContextAware) jsonMarshal).setCamelContext(camelContext); } if (jsonUnmarshal instanceof CamelContextAware) { ((CamelContextAware) jsonUnmarshal).setCamelContext(camelContext); } if (xmlMarshal instanceof CamelContextAware) { ((CamelContextAware) xmlMarshal).setCamelContext(camelContext); } if (xmlUnmarshal instanceof CamelContextAware) { ((CamelContextAware) xmlUnmarshal).setCamelContext(camelContext); } ServiceHelper.startServices(jsonMarshal, jsonUnmarshal, xmlMarshal, xmlUnmarshal); }
protected void setUp(String endpointUri) throws Exception { template = camelContext.createProducerTemplate(); startServices(template, camelContext); endpoint = camelContext.getEndpoint(endpointUri, JpaEndpoint.class); transactionStrategy = endpoint.createTransactionStrategy(); jpaTemplate = endpoint.getTemplate(); transactionStrategy.execute( new JpaCallback() { public Object doInJpa(EntityManager entityManager) throws PersistenceException { entityManager.createQuery("delete from " + Customer.class.getName()).executeUpdate(); return null; } }); assertEntitiesInDatabase(0, Customer.class.getName()); assertEntitiesInDatabase(0, Address.class.getName()); }
protected void doStart() throws Exception { if (isParallelProcessing() && executorService == null) { throw new IllegalArgumentException( "ParallelProcessing is enabled but ExecutorService has not been set"); } if (timeout > 0 && !isParallelProcessing()) { throw new IllegalArgumentException( "Timeout is used but ParallelProcessing has not been enabled"); } if (isParallelProcessing() && aggregateExecutorService == null) { // use unbounded thread pool so we ensure the aggregate on-the-fly task always will have // assigned a thread // and run the tasks when the task is submitted. If not then the aggregate task may not be // able to run // and signal completion during processing, which would lead to what would appear as a // dead-lock or a slow processing String name = getClass().getSimpleName() + "-AggregateTask"; aggregateExecutorService = createAggregateExecutorService(name); } ServiceHelper.startServices(aggregationStrategy, processors); }
protected void doStart() throws Exception { ServiceHelper.startServices(aggregationStrategy, consumer); }
protected void doStart() throws Exception { log.debug("Starting consumer: {}", this); ServiceHelper.startServices(processor); }
@Override protected void doStart() throws Exception { ServiceHelper.startServices(target, interceptor); }