On Tue, Nov 8, 2011 at 2:13 PM, wing-tung Leung <wingtung.le...@gmail.com> wrote: > Hello, > > my camel context contains a few routes which should not be started > automatically, but it should run a business check first for those routes. > My initial idea is to disable "autoStartup" for those routes, and add a > custom StartupListener which performs the check and simply calls > "startRoute()" on the context if the check passes. > > But, this fails to work because "DefaultCamelContext.startRouteService()" > checks the camel context is already started or not, and the listeners are > already invoked BEFORE setting the "started" flag, just AFTER starting all > relevant routes. > > Listeners are called in the "doStart()" method, BEFORE setting the > "started" flag: > > https://github.com/apache/camel/blob/trunk/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java#L51 > > I have the feeling that the documentation of the StartupListener can be > improved here, or should the listeners be invoked AFTER the complete start > of the context? > > http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/StartupListener.html >
Yes thats the intend of this listener. To allow components, to listen in and do any custom work they need, before any routes is started. For example the quartz component uses this to ensure the quartz scheduler do not get started to early and trigger events, which otherwise could cause problems. There is a RoutePolicy and it have an onInit method. But I can't recall if that method is invoked even if the route has auto startup = false. But again if you use Spring XML, you can also just add a <bean> which have a depens-on the id of the <camelContext>. Then Spring ought to startup Camel, before the <bean>. > If this is intended behavior: other ideas to achieve my goal? Starting > routes in "suspended" mode? Use separate Spring bean and "depends-on" which > starts the routes AFTER the complete startup of the initial context? > > (running on camel 2.6.0, but the related code looks similar in current > trunk) > > Any advice is greatly appreciated, > > Tung > -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/