in my java based camel app i want create a central class that controls all
routes (starting, stopping) but i don't want any route be aware of this
class. routes should keep untouched on any changes of route control, like
refactoring.
My app uses guice (DI) and at the moment i began with a simple class
RouteControl that has one method and injects the camel context. here is the
method:
/**
* Starts all routes found in context.
*/
public void startAll() {
log.info("starting all routes.");
for (RouteDefinition route : ((ModelCamelContext)
context).getRouteDefinitions()) {
String id = route.getId();
try {
log.info("starting route " + id);
context.startRoute(id);
} catch (Exception e) {
throw new IllegalStateException("Unable to start route " + id +
" cause, ", e);
The problem is that is not working. On log i see "starting route" for each
route but then "DefaultCamelContext INFO Total 2 routes, of
which 0 is started."
I am unsure if the method is wrong or how it is invoked. here is my
main-method:
public static void main(final String... args) throws Exception {
Injector i;
if (args.length < 1 || Strings.isNullOrEmpty(args[0])) {
i = Guice.createInjector(new CepModule());
} else {
i = Guice.createInjector(new CepModule(args[0]));
OurMain main = i.getInstance(OurMain.class);
// eliminates logging to java.util.logger
SLF4JBridgeHandler.removeHandlersForRootLogger();
// redirects all java.util.logger stuff to slf4j
SLF4JBridgeHandler.install();
i.getInstance(RouteControl.class).startAll();
main.enableHangupSupport();
main.run();
routes (starting, stopping) but i don't want any route be aware of this
class. routes should keep untouched on any changes of route control, like
refactoring.
My app uses guice (DI) and at the moment i began with a simple class
RouteControl that has one method and injects the camel context. here is the
method:
/**
* Starts all routes found in context.
*/
public void startAll() {
log.info("starting all routes.");
for (RouteDefinition route : ((ModelCamelContext)
context).getRouteDefinitions()) {
String id = route.getId();
try {
log.info("starting route " + id);
context.startRoute(id);
} catch (Exception e) {
throw new IllegalStateException("Unable to start route " + id +
" cause, ", e);
The problem is that is not working. On log i see "starting route" for each
route but then "DefaultCamelContext INFO Total 2 routes, of
which 0 is started."
I am unsure if the method is wrong or how it is invoked. here is my
main-method:
public static void main(final String... args) throws Exception {
Injector i;
if (args.length < 1 || Strings.isNullOrEmpty(args[0])) {
i = Guice.createInjector(new CepModule());
} else {
i = Guice.createInjector(new CepModule(args[0]));
OurMain main = i.getInstance(OurMain.class);
// eliminates logging to java.util.logger
SLF4JBridgeHandler.removeHandlersForRootLogger();
// redirects all java.util.logger stuff to slf4j
SLF4JBridgeHandler.install();
i.getInstance(RouteControl.class).startAll();
main.enableHangupSupport();
main.run();