use of org.apache.camel.RouteAware in project camel by apache.
the class RouteService method doWarmUp.
protected synchronized void doWarmUp() throws Exception {
if (endpointDone.compareAndSet(false, true)) {
// and whatnot, thus their lifecycle is to start once, and only to stop when Camel shutdown
for (Route route : routes) {
// ensure endpoint is started first (before the route services, such as the consumer)
ServiceHelper.startService(route.getEndpoint());
}
}
if (warmUpDone.compareAndSet(false, true)) {
for (Route route : routes) {
try (MDCHelper mdcHelper = new MDCHelper(route.getId())) {
// warm up the route first
route.warmUp();
LOG.debug("Starting services on route: {}", route.getId());
List<Service> services = route.getServices();
// callback that we are staring these services
route.onStartingServices(services);
// gather list of services to start as we need to start child services as well
Set<Service> list = new LinkedHashSet<Service>();
for (Service service : services) {
list.addAll(ServiceHelper.getChildServices(service));
}
// split into consumers and child services as we need to start the consumers
// afterwards to avoid them being active while the others start
List<Service> childServices = new ArrayList<Service>();
for (Service service : list) {
// inject the route
if (service instanceof RouteAware) {
((RouteAware) service).setRoute(route);
}
if (service instanceof Consumer) {
inputs.put(route, (Consumer) service);
} else {
childServices.add(service);
}
}
startChildService(route, childServices);
// fire event
EventHelper.notifyRouteAdded(camelContext, route);
}
}
// ensure lifecycle strategy is invoked which among others enlist the route in JMX
for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
strategy.onRoutesAdd(routes);
}
// add routes to camel context
camelContext.addRouteCollection(routes);
}
}
use of org.apache.camel.RouteAware in project camel by apache.
the class EventDrivenConsumerRoute method addServices.
/**
* Factory method to lazily create the complete list of services required for this route
* such as adding the processor or consumer
*/
@Override
protected void addServices(List<Service> services) throws Exception {
Endpoint endpoint = getEndpoint();
consumer = endpoint.createConsumer(processor);
if (consumer != null) {
services.add(consumer);
if (consumer instanceof RouteAware) {
((RouteAware) consumer).setRoute(this);
}
}
Processor processor = getProcessor();
if (processor instanceof Service) {
services.add((Service) processor);
}
}
Aggregations