Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Bundle Starting order
Bundle Starting order [message #80322] Mon, 08 January 2007 05:20 Go to next message
Eclipse UserFriend
Originally posted by: devquest.yahoo.co.in

I have a few queries regarding the starting order of bundles.

From the documentation I find that bundles can be started by specifying "osgi.bundles" property in the config.ini file(They are a comma-separated list of bundles which are automatically installed and optionally started).

I am trying to use the LogService in the start() method of my Bundle. The bundle code is shown below

package helloworld;

import java.util.Date;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;


public class Activator implements BundleActivator , ServiceListener {

private BundleContext m_context;
/**
* Implements BundleActivator.start(). Prints
* a message and adds itself to the bundle context as a service
* listener.
* @param context the framework context for the bundle.
**/
public void start(BundleContext context)
{
System.out.println("Starting to listen for service events.");
m_context=context;
context.addServiceListener(this);
ServiceReference s = context.getServiceReference(org.osgi.service.log.LogService. class.getName());
if(s != null) {
LogService ls = (LogService)context.getService(s);
if(ls != null) {
ls.log(LogService.LOG_ERROR,"Hello from log");
}
} else {
System.out.println("No log service...");
}
}

/**
* Implements BundleActivator.stop(). Prints
* a message and removes itself from the bundle context as a
* service listener.
* @param context the framework context for the bundle.
**/
public void stop(BundleContext context)
{
context.removeServiceListener(this);
System.out.println("Stopped listening for service events.");
m_thread.interrupt();
// Note: It is not required that we remove the listener here,
// since the framework will do it automatically anyway.
}

/**
* Implements ServiceListener.serviceChanged().
* Prints the details of any service event from the framework.
* @param event the fired service event.
**/
public void serviceChanged(ServiceEvent event)
{
String[] objectClass = (String[])
event.getServiceReference().getProperty("objectClass");

if (event.getType() == ServiceEvent.REGISTERED)
{
System.out.println(
"Ex1: Service of type " + objectClass[0] + " registered.");
ServiceReference s = m_context.getServiceReference("org.osgi.service.log.LogReaderService ");
}
else if (event.getType() == ServiceEvent.UNREGISTERING)
{
System.out.println(
"Ex1: Service of type " + objectClass[0] + " unregistered.");
}
else if (event.getType() == ServiceEvent.MODIFIED)
{
System.out.println(
"Ex1: Service of type " + objectClass[0] + " modified.");
}
}
}

When I specify the osgi.bundles property(shown below) such that the org.eclipse.equinox.log_xxx bundle is started before the helloworld_1_0_0 bundle, LogService is accessable.

osgi.bundles=org.eclipse.osgi.services_3.1.100.v20060601.jar@start,org.eclipse.equinox.log_1.0.1.R32x_v20060717.jar@start,helloworld_1.0.0.jar@start

============================================================ ==========================
osgi> Starting to listen for service events.


osgi> log
>Info [2] Log created; Log Size=100; Log Threshold=4 initial@reference:file:org.eclipse.equinox.log_1.0.1.R32x_v20060717.jar/
>Info [2] ServiceEvent REGISTERED {service.id=20}
>Info [2] ServiceEvent REGISTERED {service.id=21}
>Info [2] ServiceEvent REGISTERED {service.id=22}
>Info [2] BundleEvent STARTED initial@reference:file:org.eclipse.equinox.log_1.0.1.R32x_v20060717.jar/
>Error [3] Hello from log initial@reference:file:helloworld_1.0.0.jar/
>Info [3] BundleEvent STARTED initial@reference:file:helloworld_1.0.0.jar/
>Info [0] FrameworkEvent STARTLEVEL CHANGED System Bundle
============================================================ ============================


If I set the osgi.bundles property(shown below) such that the helloworld_1_0_0 bundle is started before the org.eclipse.equinox.log_xxx bundle, LogService is not accessable.

osgi.bundles=helloworld_1.0.0.jar@start,org.eclipse.osgi.services_3.1.100.v20060601.jar@start,org.eclipse.equinox.log_1.0.1.R32x_v20060717.jar@start"
============================================================ ============================
osgi> Starting to listen for service events.
No log service...
Ex1: Service of type org.osgi.service.log.LogService registered.
Ex1: Service of type org.osgi.service.log.LogReaderService registered.
Ex1: Service of type org.osgi.service.cm.ManagedService registered.
============================================================ =============================


1> Is it the responsibility of the programmer to ensure that the bundles are started in correct order and listen for "ServiceEvent"'s and take appropriate action when the desired services becomes avaiable?

2> From the Equinox Quick start guide, setting the osgi.bundles to "org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start" will give "Automatic bundle discovery/Install" for the bundles placed in the plugins directory. Is it possible to start the bundles using this method and is it possible to specify the start order?
Re: Bundle Starting order [message #80367 is a reply to message #80322] Mon, 08 January 2007 11:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

> 1> Is it the responsibility of the programmer to ensure that the
> bundles are started in correct order and listen for
> "ServiceEvent"'s and take appropriate action when the desired
> services becomes avaiable?

It's not the responsibility for the *programmer* to ensure that they're started in the correct order.

You can do that with the osgi.bundles as part of the deployment.

What the programmer is supposed to do is to have code that deals with the services arriving and departing through the lifetime of your bundle. In other words, you can't guarantee that the LogService will always be present, and you should code appropriatly defensively for this situation. Whether you chose to batch up log messages or not is up to you.

> 2> From the Equinox Quick start guide, setting the osgi.bundles
> to "org.eclipse.equinox.common@2:start,
> org.eclipse.update.configurator@3:start" will give "Automatic
> bundle discovery/Install" for the bundles placed in the plugins
> directory. Is it possible to start the bundles using this
> method and is it possible to specify the start order?

You can do this; I don't know what the ordering will be, though, and you can't change that.

What you can do is to use the osgi.bundles to start the log service first, and then use the org.eclipse.update.configurator@3:start afterwards. The number (3) is the start level, so you could have e.g. org.eclipse.equinox.common@2:start,
org.eclipse.equinox.log@3:start,
org.eclipse.update.configurator@4:start

That way, the common stuff comes up first, the log comes up second, and then everything else in the update configurator starts third, which would seem to do what you want.

Alex.
Re: Bundle Starting order [message #80381 is a reply to message #80367] Mon, 08 January 2007 14:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: devquest.yahoo.co.in

Thanks for the details.

I set the osgi.bundles to the values that were suggested. However the "helloworld" bundle state is "RESOLVED".It is not ACTIVE.

The "Equinox Quick Start Guide" mentions the following

"Update configurator bundle starts, it automatically discovers and installs all the bundles in the plugins directory that is beside the Equinox JAR. Note that the configurator does not automatically start these bundles"

Is it possible to configure the update configurator to autostart the bundles that it finds in the plugin directory?


Thanks,
Arun
Re: Bundle Starting order [message #80396 is a reply to message #80381] Mon, 08 January 2007 15:55 Go to previous message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

You wouldn't want to autostart everything; that would (potentially) take too long. That being said, for a reduced subset, you might be able to do it yourself but I don't believe that the Equinox configurator will.

Shouldn't be too hard to write a bundle that lists through all the installed bundles and start them though, should it?

Alex.
Previous Topic:Eclipse RCP Plugin with an RMIClassloader
Next Topic:Embedding Equinox in a Standalone Application
Goto Forum:
  


Current Time: Thu Apr 25 20:33:49 GMT 2024

Powered by FUDForum. Page generated in 0.03569 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top