Reputation: 2951
I have one java application which uses OSGI model :
I have two preexisting bundles :
com.login
has a implementation and registration of Authenticator
service (own service for authentication).com.login
as well as com.mos
uses this authentication service.
Now I am writing one new bundle (com.new
) and I have to add / modify Authenticator Service so I have written my own implementation of it.
Once I start my program / application, if my new bundle com.new
runs after com.login
then all bundles uses new Authenticator Service
.But If com.new
bundles runs before com.login
then old Authenticator Service
is available.
Is there any mechanism in OSGI
where we give some priority something like which bundle should start first.
Upvotes: 2
Views: 1861
Reputation: 291
In general, when you have multiple OSGi services available, you have two options to pick one:
Service Filter can be used to filter out services based on service properties as described here or here.
Service Ranking published by the service makes them eligible to be picked up based on the service ranking. The one with highest service ranking will be picked up as described here or here.
According to the documentation of the BundleContext.getServiceReference() method:
If multiple such services exist, the service with the highest priority is selected. This priority is defined as the service reference with the highest ranking (as specified in its Constants.SERVICE_RANKING property) is returned.
If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was registered first is returned.
Upvotes: 2
Reputation: 1312
The OSGi bundle startlevels allow you to influence the start order for each bundle. See the according javadocs http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/startlevel/package-summary.html But I would not recommend to do that. Start levels should usually not be used as a way to control service startup. In OSGi service start orders are not guaranteed and services may come and go at will.
Making your new bundle (com.new) depending on the specific implementation of your Authenticator service would do the trick and guarante the correct order.
Upvotes: 1