Need to execute code while uninstalling application on Karaf

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Need to execute code while uninstalling application on Karaf

Prithviraj
Hi ,

We are using Mbeans in our application running on Karaf server.
Now our requirement is while uninstalling our application , we need to uninstall Mbeans  which are added by us.
I am aware of  way to execute code while  start up of Karaf server  .
Is there any way  to execute code  while stopping /uninstall ?

Thanks in advance .

Thanks,
Prithvi
Reply | Threaded
Open this post in threaded view
|

Re: Need to execute code while uninstalling application on Karaf

Guillaume Nodet-2
What do you refer to as "installing your application" and "uninstalling
your application".
I suppose MBeans are registered when some bundles are started (not
installed).
If so, you simply need to unregister them when the bundle is stopped (not
uninstalled).

Guillaume

2015-01-27 8:50 GMT+01:00 Prithviraj <[hidden email]>:

> Hi ,
>
> We are using Mbeans in our application running on Karaf server.
> Now our requirement is while uninstalling our application , we need to
> uninstall Mbeans  which are added by us.
> I am aware of  way to execute code while  start up of Karaf server  .
> Is there any way  to execute code  while stopping /uninstall ?
>
> Thanks in advance .
>
> Thanks,
> Prithvi
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Need-to-execute-code-while-uninstalling-application-on-Karaf-tp4038037.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Need to execute code while uninstalling application on Karaf

Prithviraj
Hi Guillaume,

Yes  as  you mentioned  we need to unregister  MBean while bundle is getting stoped.
I want to know where i can do that configuration  so that my code for  unregister  MBean while bundle is getting stoped.
Thanks in advance . 



On Tue, Jan 27, 2015 at 5:46 PM, Guillaume Nodet-2 [via Karaf] <[hidden email]> wrote:
What do you refer to as "installing your application" and "uninstalling
your application".
I suppose MBeans are registered when some bundles are started (not
installed).
If so, you simply need to unregister them when the bundle is stopped (not
uninstalled).

Guillaume

2015-01-27 8:50 GMT+01:00 Prithviraj <[hidden email]>:

> Hi ,
>
> We are using Mbeans in our application running on Karaf server.
> Now our requirement is while uninstalling our application , we need to
> uninstall Mbeans  which are added by us.
> I am aware of  way to execute code while  start up of Karaf server  .
> Is there any way  to execute code  while stopping /uninstall ?
>
> Thanks in advance .
>
> Thanks,
> Prithvi
>
>
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Need-to-execute-code-while-uninstalling-application-on-Karaf-tp4038037.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.
>



If you reply to this email, your message will be added to the discussion below:
http://karaf.922171.n3.nabble.com/Need-to-execute-code-while-uninstalling-application-on-Karaf-tp4038037p4038042.html
To unsubscribe from Need to execute code while uninstalling application on Karaf, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Need to execute code while uninstalling application on Karaf

cschneider
In reply to this post by Prithviraj
Instead of installing mbeans directly you can also use aries-jmx and
simply export the mbeans as OSGi services and let aries publish them
according to the whiteboard pattern.

This has two advantages:
1. You do not have to do extra handling when no MBeanServer is there
2. You do not have to clean up when stopping your bundles as all its
services are unregistered anyway.

Christian

On 27.01.2015 08:50, Prithviraj wrote:

> Hi ,
>
> We are using Mbeans in our application running on Karaf server.
> Now our requirement is while uninstalling our application , we need to
> uninstall Mbeans  which are added by us.
> I am aware of  way to execute code while  start up of Karaf server  .
> Is there any way  to execute code  while stopping /uninstall ?
>
> Thanks in advance .
>
> Thanks,
> Prithvi
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Need-to-execute-code-while-uninstalling-application-on-Karaf-tp4038037.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.


--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

Reply | Threaded
Open this post in threaded view
|

Re: Need to execute code while uninstalling application on Karaf

Prithviraj
Do we have any sample example of it , which i can follow ?
Reply | Threaded
Open this post in threaded view
|

Re: Need to execute code while uninstalling application on Karaf

cschneider
Almost all karaf modules use this.

As an example look at this:
https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=blob;f=bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/osgi/Activator.java;h=c5c765b18d006a4053a0a66c5d02600259ab94dd;hb=HEAD

I have condensed the code a bit:
BundlesMBeanImpl bundlesMBeanImpl = new BundlesMBeanImpl(bundleContext,
bundleService);
Hashtable<String, Object> props = new Hashtable<>();
props.put("jmx.objectname", "org.apache.karaf:type=bundle,name=" +
System.getProperty("karaf.name"));
bundleContext.registerService(getInterfaceNames(mbean), mbean, props);

Also see:
http://aries.apache.org/modules/jmx.html

Christian

On 27.01.2015 13:32, Prithviraj wrote:
> Do we have any sample example of it , which i can follow ?
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Need-to-execute-code-while-uninstalling-application-on-Karaf-tp4038037p4038045.html
> Sent from the Karaf - Dev mailing list archive at Nabble.com.


--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com