You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by bobshort <je...@check-it.ca> on 2012/05/03 17:28:58 UTC

Is there a way to query osgi framework status (e.g. started)?

We have bundles that do some intensive processing. Right now they are
starting as the framework is starting and slowing startup down considerably.
The osgi container is running on a plug computer so resources are minimal.

I want to start my processing only after the osgi container is fully
started. I've implemented a framework listener to detect when the framework
is started and then trigger my startup logic:

/public class EventListener implements FrameworkListener {
	
	@Override
	public void frameworkEvent(FrameworkEvent event) {
		if (event.getType() == FrameworkEvent.STARTED) {
			// Do startup logic here.
		}
	}
}/

This works if my bundles are installed before the framework is started, but
it obviously does not work for modules installed after the framework is
started.

Is there any way I can query the framework status from my bundle so I can
detect if the container is already fully started when the bundle is
installed? I'd like to do something like:

/
	public void onBundleStarted() {
		if (**test if framework already running**) {
			// Do startup logic here.
		}
	}
/

Is this possible?

--
View this message in context: http://karaf.922171.n3.nabble.com/Is-there-a-way-to-query-osgi-framework-status-e-g-started-tp3959588.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Is there a way to query osgi framework status (e.g. started)?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

you can add a BundleListener and check if the state of the bundle of ID 0.

Anyway it looks weird to me to define some logic at startup. Why not 
using a bootFeature or a startup bundle ?

Regards
JB

On 05/03/2012 05:28 PM, bobshort wrote:
> We have bundles that do some intensive processing. Right now they are
> starting as the framework is starting and slowing startup down considerably.
> The osgi container is running on a plug computer so resources are minimal.
>
> I want to start my processing only after the osgi container is fully
> started. I've implemented a framework listener to detect when the framework
> is started and then trigger my startup logic:
>
> /public class EventListener implements FrameworkListener {
> 	
> 	@Override
> 	public void frameworkEvent(FrameworkEvent event) {
> 		if (event.getType() == FrameworkEvent.STARTED) {
> 			// Do startup logic here.
> 		}
> 	}
> }/
>
> This works if my bundles are installed before the framework is started, but
> it obviously does not work for modules installed after the framework is
> started.
>
> Is there any way I can query the framework status from my bundle so I can
> detect if the container is already fully started when the bundle is
> installed? I'd like to do something like:
>
> /
> 	public void onBundleStarted() {
> 		if (**test if framework already running**) {
> 			// Do startup logic here.
> 		}
> 	}
> /
>
> Is this possible?
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Is-there-a-way-to-query-osgi-framework-status-e-g-started-tp3959588.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Is there a way to query osgi framework status (e.g. started)?

Posted by Achim Nierbeck <bc...@googlemail.com>.
Well the framework is just the osgi framework.
You might try with start levels, to start your bundle in one of the
"last" start levels

regards, Achim

2012/5/3 bobshort <je...@check-it.ca>:
> We have bundles that do some intensive processing. Right now they are
> starting as the framework is starting and slowing startup down considerably.
> The osgi container is running on a plug computer so resources are minimal.
>
> I want to start my processing only after the osgi container is fully
> started. I've implemented a framework listener to detect when the framework
> is started and then trigger my startup logic:
>
> /public class EventListener implements FrameworkListener {
>
>        @Override
>        public void frameworkEvent(FrameworkEvent event) {
>                if (event.getType() == FrameworkEvent.STARTED) {
>                        // Do startup logic here.
>                }
>        }
> }/
>
> This works if my bundles are installed before the framework is started, but
> it obviously does not work for modules installed after the framework is
> started.
>
> Is there any way I can query the framework status from my bundle so I can
> detect if the container is already fully started when the bundle is
> installed? I'd like to do something like:
>
> /
>        public void onBundleStarted() {
>                if (**test if framework already running**) {
>                        // Do startup logic here.
>                }
>        }
> /
>
> Is this possible?
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Is-there-a-way-to-query-osgi-framework-status-e-g-started-tp3959588.html
> Sent from the Karaf - User mailing list archive at Nabble.com.



-- 

Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/>
Committer & Project Lead
OPS4J Pax Vaadin <http://team.ops4j.org/wiki/display/PAXVAADIN/Home>
Commiter & Project Lead
blog <http://notizblog.nierbeck.de/>

Re: Is there a way to query osgi framework status (e.g. started)?

Posted by bobshort <je...@check-it.ca>.
Thanks for the replies!

The main thing I'm trying to accomplish is to not start expensive processing
while the framework is booting. On a embedded ARM device it can take
framework startup times from 2 min to +5 min. 

I was thinking of trying a bundle with a very high run level and use it to
signal all other bundles to start. I'll give that go and see how well it
works.

--
View this message in context: http://karaf.922171.n3.nabble.com/Is-there-a-way-to-query-osgi-framework-status-e-g-started-tp3959588p3959787.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Is there a way to query osgi framework status (e.g. started)?

Posted by Guillaume Nodet <gn...@gmail.com>.
There's no such thing as a 'started' state.  The osgi framework is fully
asynchronous and things can even be done on behalf of other bundles.  The
only real way to know if 'something' is started is to have this thing
register an osgi service when started and wait for this service to be
registered.  A lot of bundles do behave in this way so that you have
inter-bundles dependencies using services.  But at the end, 'started'
depends on what meaning you put behind this word, and that mostly depends
on what you deploy.

On Thu, May 3, 2012 at 5:28 PM, bobshort <je...@check-it.ca> wrote:

> We have bundles that do some intensive processing. Right now they are
> starting as the framework is starting and slowing startup down
> considerably.
> The osgi container is running on a plug computer so resources are minimal.
>
> I want to start my processing only after the osgi container is fully
> started. I've implemented a framework listener to detect when the framework
> is started and then trigger my startup logic:
>
> /public class EventListener implements FrameworkListener {
>
>        @Override
>        public void frameworkEvent(FrameworkEvent event) {
>                if (event.getType() == FrameworkEvent.STARTED) {
>                        // Do startup logic here.
>                }
>        }
> }/
>
> This works if my bundles are installed before the framework is started, but
> it obviously does not work for modules installed after the framework is
> started.
>
> Is there any way I can query the framework status from my bundle so I can
> detect if the container is already fully started when the bundle is
> installed? I'd like to do something like:
>
> /
>        public void onBundleStarted() {
>                if (**test if framework already running**) {
>                        // Do startup logic here.
>                }
>        }
> /
>
> Is this possible?
>
> --
> View this message in context:
> http://karaf.922171.n3.nabble.com/Is-there-a-way-to-query-osgi-framework-status-e-g-started-tp3959588.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>



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