karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raman Gupta <rocketra...@gmail.com>
Subject Re: RFC on proposal to allow hooks into Karaf shutdown
Date Fri, 30 Nov 2012 13:48:45 GMT
Great guys, thanks. This is why I wanted to do the RFC before hacking 
away. When in doubt, always assume the proposal is stupid :)

Regards,
Raman

On Fri 30 Nov 2012 05:10:59 AM EST, Jean-Baptiste Onofré wrote:
> No problem ;)
>
> We are inline ;)
>
> Regards
> JB
>
> On 11/30/2012 10:56 AM, Guillaume Nodet wrote:
>> Sorry about the duplicate answer, I should have gone through the
>> entire
>> thread before answering ;-)
>>
>>
>> On Fri, Nov 30, 2012 at 10:55 AM, Guillaume Nodet
>> <gnodet@gmail.com> wrote:
>>
>>> 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
View raw message