use of org.apache.camel.Route in project camel by apache.
the class DefaultManagementLifecycleStrategy method onRoutesAdd.
public void onRoutesAdd(Collection<Route> routes) {
for (Route route : routes) {
// enabled, then enlist the route as a known route
if (getCamelContext().getStatus().isStarting() || getManagementStrategy().getManagementAgent().getRegisterAlways() || getManagementStrategy().getManagementAgent().getRegisterNewRoutes()) {
// register as known route id
knowRouteIds.add(route.getId());
}
if (!shouldRegister(route, route)) {
// avoid registering if not needed, skip to next route
continue;
}
Object mr = getManagementObjectStrategy().getManagedObjectForRoute(camelContext, route);
// skip already managed routes, for example if the route has been restarted
if (getManagementStrategy().isManaged(mr, null)) {
LOG.trace("The route is already managed: {}", route);
continue;
}
// and set me as the counter
if (route instanceof EventDrivenConsumerRoute) {
EventDrivenConsumerRoute edcr = (EventDrivenConsumerRoute) route;
Processor processor = edcr.getProcessor();
if (processor instanceof CamelInternalProcessor && mr instanceof ManagedRoute) {
CamelInternalProcessor internal = (CamelInternalProcessor) processor;
ManagedRoute routeMBean = (ManagedRoute) mr;
CamelInternalProcessor.InstrumentationAdvice task = internal.getAdvice(CamelInternalProcessor.InstrumentationAdvice.class);
if (task != null) {
// we need to wrap the counter with the camel context so we get stats updated on the context as well
if (camelContextMBean != null) {
CompositePerformanceCounter wrapper = new CompositePerformanceCounter(routeMBean, camelContextMBean);
task.setCounter(wrapper);
} else {
task.setCounter(routeMBean);
}
}
}
}
try {
manageObject(mr);
} catch (JMException e) {
LOG.warn("Could not register Route MBean", e);
} catch (Exception e) {
LOG.warn("Could not create Route MBean", e);
}
}
}
use of org.apache.camel.Route in project camel by apache.
the class StartStopAndShutdownRouteTest method testStartStopAndShutdownRoute.
public void testStartStopAndShutdownRoute() throws Exception {
// there should still be 2 services on the route
Route myRoute = context.getRoute("foo");
int services = myRoute.getServices().size();
assertTrue(services > 0);
// stop the route
context.stopRoute("foo");
// there should still be the same number of services on the route
assertEquals(services, myRoute.getServices().size());
// shutting down the route, by stop and remove
context.stopRoute("foo");
context.removeRoute("foo");
// and now no more services as the route is shutdown
assertEquals(0, myRoute.getServices().size());
}
use of org.apache.camel.Route in project camel by apache.
the class RoutePolicySupportTest method testLifecycleCallbacks.
@Test
public void testLifecycleCallbacks() throws Exception {
Route route = context.getRoute("foo");
assertEquals(ServiceStatus.Stopped, context.getRouteStatus("foo"));
policy.startRoute(route);
assertEquals(ServiceStatus.Started, context.getRouteStatus("foo"));
policy.suspendRoute(route);
assertEquals(ServiceStatus.Suspended, context.getRouteStatus("foo"));
policy.resumeRoute(route);
assertEquals(ServiceStatus.Started, context.getRouteStatus("foo"));
policy.stopRoute(route);
assertEquals(ServiceStatus.Stopped, context.getRouteStatus("foo"));
}
use of org.apache.camel.Route in project camel by apache.
the class RouteSedaStopStartTest method testStopStart.
public void testStopStart() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A");
template.sendBody("seda:foo", "A");
assertMockEndpointsSatisfied();
log.info("Stopping");
// now suspend and dont expect a message to be routed
resetMocks();
mock.expectedMessageCount(0);
context.stopRoute("foo");
assertEquals("Stopped", context.getRouteStatus("foo").name());
Route route = context.getRoute("foo");
if (route instanceof StatefulService) {
assertEquals("Stopped", ((StatefulService) route).getStatus().name());
}
template.sendBody("seda:foo", "B");
mock.assertIsSatisfied(1000);
log.info("Starting");
// now resume and expect the previous message to be routed
resetMocks();
mock.expectedBodiesReceived("B");
context.startRoute("foo");
assertMockEndpointsSatisfied();
assertEquals("Started", context.getRouteStatus("foo").name());
route = context.getRoute("foo");
if (route instanceof StatefulService) {
assertEquals("Started", ((StatefulService) route).getStatus().name());
}
}
use of org.apache.camel.Route in project camel by apache.
the class ConsulRoutePolicy method startAllStoppedConsumers.
private void startAllStoppedConsumers() {
synchronized (lock) {
try {
for (Route route : suspendedRoutes) {
LOGGER.debug("Starting consumer for {} ({})", route.getId(), route.getConsumer());
startConsumer(route.getConsumer());
}
suspendedRoutes.clear();
} catch (Exception e) {
handleException(e);
}
}
}
Aggregations