On Fri, Nov 9, 2012 at 9:42 AM, Bernard Ligny <bernard.li...@gmail.com> wrote: > > > Willem.Jiang wrote >> Did you create the camel context in the BundleActivator or using >> Blueprint, Spring to create the camel context? > > It is created using Spring, > (but my osgi bundle activator is registered through the manifest, not by > Spring) > > > Willem.Jiang wrote >> Why do you need to access the camel context when the bundle is stop? > > Because upon shutdown, I need to persist some statistics into a database. > And this persistency job is provided by Spring beans (dao and service - in > the Spring meaning, not osgi - implementations). > eg: > > ServiceReference[] references = > bundleContext.getServiceReferences(CamelContext.class.getName(), null); > CamelContext cc = null; > if ( references != null && references.length>0 ) { > cc = (CamelContext) bundleContext.getService(references[0]); > MySpringBean bean = Pcc.getRegistry().lookup("myBean", > MySpringBean.class); > bean.persistStats(); > } > > So the question is: where can we place some "finalization" work when a camel > context context (created by Spring) is shut down ? Note that as that work is > delegating most of a job to spring beans, all these beans must not be > deregistered yet. In that sense, it is more a "*before*-shutdown" hook that > we really need in my case... >
You can maybe just define a Spring <bean> and have a stop method being invoked from it. There is a attribute you can set in the <bean> to refer to a start|stop method. And then have maybe a "depends-on" -> Camel is needed. To help Spring with the ordering. <bean id="myStatBean" depends-on="myCamel"> <camelContext id="myCamel" ...> > > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Access-camel-context-from-BundleActivator-stop-tp5722376p5722381.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- Red Hat, Inc. FuseSource is now part of Red Hat Email: cib...@redhat.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen