use of org.apache.camel.Route in project camel by apache.
the class RandomLoadBalanceJavaDSLBuilderTest method testNavigateRouteAsJavaDSLWithNavigate.
public void testNavigateRouteAsJavaDSLWithNavigate() throws Exception {
// this one navigate using the runtime route using the Navigate<Processor>
StringBuilder sb = new StringBuilder();
Route route = context.getRoutes().get(0);
// the start of the route
sb.append("from(\"" + route.getEndpoint().getEndpointUri() + "\")");
// navigate the route and add Java DSL to the sb
Navigate<Processor> nav = route.navigate();
navigateRoute(nav, sb);
// output the Java DSL
assertEquals("from(\"direct://start\").loadBalance().random().to(\"mock://x\").to(\"mock://y\").to(\"mock://z\")", sb.toString());
}
use of org.apache.camel.Route in project camel by apache.
the class DefaultCamelContext method doSuspend.
@Override
protected void doSuspend() throws Exception {
EventHelper.notifyCamelContextSuspending(this);
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspending");
StopWatch watch = new StopWatch();
// (so when we resume we only resume the routes which actually was suspended)
for (Map.Entry<String, RouteService> entry : getRouteServices().entrySet()) {
if (entry.getValue().getStatus().isStarted()) {
suspendedRouteServices.put(entry.getKey(), entry.getValue());
}
}
// assemble list of startup ordering so routes can be shutdown accordingly
List<RouteStartupOrder> orders = new ArrayList<RouteStartupOrder>();
for (Map.Entry<String, RouteService> entry : suspendedRouteServices.entrySet()) {
Route route = entry.getValue().getRoutes().iterator().next();
Integer order = entry.getValue().getRouteDefinition().getStartupOrder();
if (order == null) {
order = defaultRouteStartupOrder++;
}
orders.add(new DefaultRouteStartupOrder(order, route, entry.getValue()));
}
// suspend routes using the shutdown strategy so it can shutdown in correct order
// routes which doesn't support suspension will be stopped instead
getShutdownStrategy().suspend(this, orders);
// mark the route services as suspended or stopped
for (RouteService service : suspendedRouteServices.values()) {
if (routeSupportsSuspension(service.getId())) {
service.suspend();
} else {
service.stop();
}
}
watch.stop();
if (log.isInfoEnabled()) {
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspended in " + TimeUtils.printDuration(watch.taken()));
}
EventHelper.notifyCamelContextSuspended(this);
}
use of org.apache.camel.Route in project camel by apache.
the class DefaultManagementLifecycleStrategy method onRoutesRemove.
public void onRoutesRemove(Collection<Route> routes) {
// the agent hasn't been started
if (!initialized) {
return;
}
for (Route route : routes) {
Object mr = getManagementObjectStrategy().getManagedObjectForRoute(camelContext, route);
// skip unmanaged routes
if (!getManagementStrategy().isManaged(mr, null)) {
LOG.trace("The route is not managed: {}", route);
continue;
}
try {
unmanageObject(mr);
} catch (Exception e) {
LOG.warn("Could not unregister Route MBean", e);
}
// remove from known routes ids, as the route has been removed
knowRouteIds.remove(route.getId());
}
// after the routes has been removed, we should clear the wrapped processors as we no longer need them
// as they were just a provisional map used during creation of routes
removeWrappedProcessorsForRoutes(routes);
}
use of org.apache.camel.Route in project camel by apache.
the class DefaultManagementLifecycleStrategy method removeWrappedProcessorsForRoutes.
/**
* Removes the wrapped processors for the given routes, as they are no longer in use.
* <p/>
* This is needed to avoid accumulating memory, if a lot of routes is being added and removed.
*
* @param routes the routes
*/
private void removeWrappedProcessorsForRoutes(Collection<Route> routes) {
// loop the routes, and remove the route associated wrapped processors, as they are no longer in use
for (Route route : routes) {
String id = route.getId();
Iterator<KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor>> it = wrappedProcessors.values().iterator();
while (it.hasNext()) {
KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor> holder = it.next();
RouteDefinition def = ProcessorDefinitionHelper.getRoute(holder.getKey());
if (def != null && id.equals(def.getId())) {
it.remove();
}
}
}
}
use of org.apache.camel.Route 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());
}
Aggregations