When are OSGI Bundles activated? [message #447791] |
Sun, 16 April 2006 10:34 |
Eclipse User |
|
|
|
Originally posted by: eclipse.bitmotor.de
I have two osgi bundles (an API and an implementation bundle) and a test plugin.
The first bundle is just an api bundle, containig an interface (IApiInterface), no activator.
The second bundle contains an implementation of this interface and a BundleActivator.
The BundleActivator of the implementation registers a service into the context, implementing the
interface given by the api:
public void start(BundleContext context) throws Exception {
Properties properties = new Properties();
properties.put( "property", "de" );
context.registerService(IApiInterface.class.getName(),
new Service(), properties);
}
Now: I have a third "Hello world" kind plugin, for testing this. In the SampleAction (a default
action generated while creating the Hello World RCP project), the run Method implements something
like this:
public void run(IAction action) {
final BundleContext context = TheTestActivator.getDefault()
.getContext();
final ServiceReference[] refs;
try {
refs = context.getServiceReferences(
IApiInterface.class.getName(), "(property=*)");
} catch (InvalidSyntaxException e) {
e.printStackTrace();
return;
}
if (refs != null && refs.length != 0) {
// call the service ..
}
}
But in my case, refs is always null and while debugging I see, the BundleActivator of the
implementation bundle is never instantiated.
Only if I start the implementation bundle "manually" from the start method of my Test Plugin (in the
same way, I did in the implementation bundle), refs contains the searched bundle. So it is working
in principle, but my implementation bundle simply is not activated per default.
So I guess I misunderstood something. How do I define, that my implementation bundle is not only
installed, but usable, too? Do I have to enable it somehow in the pulgin.xml file of my Test Plugin
or something?
I hope you can help a beginner on it's way writing an Eclipse RCP app.. :-)
Thanks!
|
|
|
Re: When are OSGI Bundles activated? [message #447813 is a reply to message #447791] |
Mon, 17 April 2006 14:52 |
|
Ah, OSGi bundles.
Left to it's own devices, eclipse-OSGi starts
org.eclipse.equinox.common, org.eclipse.update.configurator, and
org.eclipse.core.runtime when it starts. It's in
eclipse/configuration/config.ini.
These three plugins cause a cascade that load the other plugins. But
most plugins in eclipse have the "Eclipse-AutoStart: true" or
"Eclipse-LazyStart: true". When another plugin tries to load a class
from your plugin, then your plugin is activated (and the start(*) method
is called). If no one tries to load a class from your plugin, it's
never activated.
This of course causes problems for plugins that are contributing
services. One option is to add your bundle to the osgi.bundles in the
config.ini. But you have to be careful to only use activated bundles
while registering your service.
If this is too low level, you could always have your service plugin use
the org.eclipse.ui.startup extension.
In both cases, be careful. Forcing early startup of a plugin can cause
a cascade that causes many other plugins to instantiate before their
functionality is truly needed. This can have performance implications
in both speed and memory. But in an RCP app you can structure your
service plugins safely and you can control who starts up when.
Later,
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Powered by
FUDForum. Page generated in 0.03082 seconds