karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Nodet <gno...@gmail.com>
Subject Re: RFC on proposal to allow hooks into Karaf shutdown
Date Fri, 30 Nov 2012 09:55:00 GMT
I'm not sure to understand the problem.
Could you please give a use case ?

if you wan to intercept the fact that the framework is being shutdown, the
easiest way is to register a SynchronousBundleListener and wait for the
bundle event STOPPING on bundle 0.
That event is sent synchronously, so all the listeners will be called
before the framework actually start the stopping process.
This is the only safe way, as hacking the Main class will not always
correct intercept the events, because the Main class only controls stopping
the framework from outside, so would not react to a call to osgi:shutdown
for example.


On Fri, Nov 30, 2012 at 5:15 AM, Raman Gupta <rocketraman@gmail.com> 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.
>
> For now, I've implemented this with a custom Karaf command that
> executes my application shutdown, and then delegates to the Karaf
> StopCommand to shutdown Karaf itself. However, this is not an ideal
> solution as it requires my custom command to be explicitly executed.
> For example, it will not run when a user does a normal kill or Ctrl-D
> in the console.
>
> Ideally, Karaf would have a "ShutdownHook" interface/service I could
> implement in my bundles -- for each one of these registered, Karaf
> would execute them before stopping the framework bundles. Based on an
> initial look at the Karaf source, I'm thinking the best place to do
> this is:
>
> ./main/src/main/java/org/apache/karaf/main/Main.java
>
> Just before the call to framework.stop(), we use the BundleContext to
> obtain and execute a shutdown method on all services that implement a
> new "FrameworkShutdownHook" interface.
>
> Then, proceed to framework.stop().
>
> Thoughts on this approach? If the devs are OK with it, I can
> implement  this.
>
> Regards,
> Raman Gupta
> Principal
> VIVO Systems
>



-- 
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message