Question

Backgroud

I'm using Equinox from within the Eclipse IDE to run a group of bundles (some of them are projects in my Eclipse working set).

After launching Equinox I would like to run some service. One option would be to use the Console which works fine, but, I would like to run something automatically after hitting the "run" button, instead of writing a command in the console window again every time.

Another special thing about the service I want to run is that it consumes another service that can only be resolved in run-time. During run-time my application checks who could provide some service and chooses between the service providers. This means that:

  • I can run my application only after all bundles were installed and started.
  • I cannot know in advance (in compile-time) which bundles my application depends on. The service provider is chosen according to run-time parameters.

My Question is:

Is there a way to register some notification in order to know when Equinox completed installing and starting all bundles its supposed to during its start-up?

If there is such a hook, I could use it to know when I could start my application.

Was it helpful?

Solution 2

Found it.

Register a Framework Event on the Bundle's activator by calling context.addFrameworkListener, and start the application when STARTED event is fired.

Works well, I just wonder whether I need to start the application on a new thread or maybe I could start my application directly from the event handler.

OTHER TIPS

I think this is a very common problem in OSGi when trying to build extensibility into your application. Let us see if I understood correctly.

You have a service interface that is used to provide some kind of extension for your bundle. Your bundle should run when all extensions have loaded.

So the problem is that you do not known when all bundles are up. Btw. if the bundles providing the service impls are using e.g. blueprint then their bundle can be Active while the blueprint extender did not yet run. So there is probably no solution to really determine when all bundles are fully started.

So in this environment there are two possible solutions:

  1. Your bundle starts to work with the existing services and listens for additional ones to come and does the necessary work to integrate these
  2. You can describe in configuration which extensions should be there. In this case each extension can register their service using a unique name in the service properties. You can then define in the config of your bundle which names need to be present before your bundle really starts.

Case 2 is used for example in CXF DOSGi. There a service endpoint can specifiy named "intents" it needs. The service endpoint is then only published when all intents are present in form of services with these names. This case is for example useful if you have a security service and your bundle may not start without it as it would be unsecured then.

Apart from these two variants I do not know of any reliable mechanism.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top