On 12/02/2012 02:44 PM, Guillaume Nodet wrote: > As I explained, I don't think that's possible. > The Main class is only responsible for shutting the framework when using > the bin/stop script and it does not have anything to do when shutting down > the framework from the inside using osgi:shutdown (or anything calling stop > on the system bundle).
It's not possible or its not optimal? Presumably, each place in the Karaf source that initiates a framework shutdown could place a "FrameworkShutdownStarted" event onto the OSGi EventAdmin? Perhaps this is also an opportunity to refactor the shutdown code and move all the framework shutdown related stuff into one place. > Another way to ensure that the listener will be called first would be to > give to its bundle a very low start level so that it's listener will be > registered first. True, but this is a bit messy. The bundle that I want to act on the event uses Spring-DM, so I can't start it before Spring-DM. I could pull out just this functionality into a separate bundle, but its a bit messy. Nevertheless, it seems to be the only option now. Regards, Raman > > On Sun, Dec 2, 2012 at 5:47 PM, Raman Gupta <[email protected]> wrote: > >> On 11/30/2012 01:56 AM, Jean-Baptiste Onofré wrote: >>> On 11/30/2012 05:15 AM, Raman Gupta wrote: >>>> I sent this to the users mailing list, but it probably belongs more on >>>> dev. I'd like to hook into the Karaf shutdown process at a higher >>>> level than the OSGi bundle shutdown. The bundle shutdown starts >>>> prematurely shutting down services and such that are necessary for >>>> work in progress to complete. >>> >>> it's more or less already available. I'm not against enhancement >>> around that, but, maybe it's redundant with the following. >>> >>> You can more or less already do something like this using a >>> SynchronousBundleListener (you will received the STOPPING event on >>> bundleId 0, so the framework), or a FrameworkListener (to hook on >>> the framework). >> >> I think there might still be some room for improvement here... >> >> The problem I'm having is that Spring-DM also hooks a >> SynchronousBundleListener into the OSGi framework. Because Spring-DM's >> listener is registered first, and executes first, it goes ahead and >> shuts down all my bundles *before* my listener gets a chance to do >> anything useful. >> >> (As an aside, for a STOPPING/STOPPED event, IMO it would make sense to >> execute listeners in reverse order i.e. the higher level listeners >> registered later should be executed first, rather than last. However, >> I guess this wasn't specified in the OSGi spec so nothing can be done >> there. There also appears to be no way specified to control the order >> explicitly.) >> >> So... I still think it would be useful if Karaf provided an event or >> hook for just before a shutdown begins. Thoughts? >> >> Regards, >> Raman >>
