You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by homeration <ch...@orange.fr> on 2012/03/23 12:12:08 UTC

Retrieves bundle registration state

Hi,

I develop a bundle that scans a list of bundles and controls their
registration states.
How can I determine that a bundle is unregistered ?

Currently, I seek all service reference's from a bundle contextand try to
determine their
registration state. Unfortunately, I did not find any property that allows
me to determine that.

Have you any idea to do this?

Thanks,

Christophe.

--
View this message in context: http://karaf.922171.n3.nabble.com/Retrieves-bundle-registration-state-tp3851245p3851245.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Retrieves bundle registration state

Posted by homeration <ch...@orange.fr>.
Thanks Lukasz.

--
View this message in context: http://karaf.922171.n3.nabble.com/Retrieves-bundle-registration-state-tp3851245p3867038.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Retrieves bundle registration state

Posted by Łukasz Dywicki <lu...@code-house.org>.
Hey,
If you need access bundle services then you can use a bundle.getBundleContext().getRegisteredServices().

One marker here - you will get list of service references only if bundle is in active state.
Aries and Spring DM by default expose the container as service. It's a bit more tricky to get state of them because container start up is asynchronous and do not block bundle to start. 

https://github.com/splatch/karaf-webconsole/blob/develop/osgi/blueprint/src/main/java/org/apache/karaf/webconsole/osgi/blueprint/BlueprintBundleStateTracker.java

This class implements two interfaces BundleListener and BlueprintListener (part of osgi-blueprint spec).

I hope this will help!

Best regards,
Lukasz Dywicki
--
Code-House
http://code-house.org

Wiadomość napisana przez homeration w dniu 26 mar 2012, o godz. 11:52:

> Thanks Lukasz.
> 
> I already use this solution to determine if bundle is active. 
> Unfortunately, this is not enough: a bundle can be active while its services
> are not started (start failure).
> In this case, karaf ssh "list" command correctly display this bundle in
> "failure" state.
> 
> I do not know how to retrieve this failure state: the function
> Bundle.getState() continues to return "Active".
> 
> Christophe.
> 
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Retrieves-bundle-registration-state-tp3851245p3857779.html
> Sent from the Karaf - User mailing list archive at Nabble.com.


Re: Retrieves bundle registration state

Posted by homeration <ch...@orange.fr>.
Thanks Lukasz.

I already use this solution to determine if bundle is active. 
Unfortunately, this is not enough: a bundle can be active while its services
are not started (start failure).
In this case, karaf ssh "list" command correctly display this bundle in
"failure" state.

I do not know how to retrieve this failure state: the function
Bundle.getState() continues to return "Active".

Christophe.

--
View this message in context: http://karaf.922171.n3.nabble.com/Retrieves-bundle-registration-state-tp3851245p3857779.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Retrieves bundle registration state

Posted by Łukasz Dywicki <lu...@code-house.org>.
You can use:
bundleContext.getBundles()[0].getState()

Below you can find an enumeration which shows usage of getState result.
https://github.com/splatch/karaf-webconsole/blob/develop/osgi/core/src/main/java/org/apache/karaf/webconsole/osgi/core/shared/State.java

Best regards,
Lukasz


Wiadomość napisana przez homeration w dniu 23 mar 2012, o godz. 12:12:

> Hi,
> 
> I develop a bundle that scans a list of bundles and controls their
> registration states.
> How can I determine that a bundle is unregistered ?
> 
> Currently, I seek all service reference's from a bundle contextand try to
> determine their
> registration state. Unfortunately, I did not find any property that allows
> me to determine that.
> 
> Have you any idea to do this?
> 
> Thanks,
> 
> Christophe.
> 
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Retrieves-bundle-registration-state-tp3851245p3851245.html
> Sent from the Karaf - User mailing list archive at Nabble.com.