Java Reference
In-Depth Information
<osgi:service
ranking="1"
interface="com.apress.springenterpriserecipes.osgi.
helloworld.service.GreeterService">
<bean class="com.apress.springenterpriserecipes.osgi.
helloworld.service.GreeterServiceImpl">
</osgi:service>
<osgi:service
ranking="2"
interface="com.apress.springenterpriserecipes.osgi.
helloworld.service.GreeterService">
<bean class="com.apress.springenterpriserecipes.osgi.
helloworld.service.GreeterServiceImpl">
</osgi:service>
If you want to bind to a specific service of a particular ranking, you can use a filter on your
osgi:reference element.
<osgi:reference id="greeterServiceReference"
interface="com.apress.springenterpriserecipes.osgi.
helloworld.service.GreeterService"
filter="( service.ranking = 1 )"
/>
Service Attributes
A more robust solution to service discrimination is service attributes. A service attribute is an arbitrary
key and value pair that the service exports, and on which lookups for a service with multiple matches
can be predicated. The service properties are specified as a Map element. You may have as many keys as
you want.
<osgi:service ref="greeterService" interface="com.apress.springenterpriserecipes.
osgi.helloworld.service.GreeterService">
<osgi:service-properties>
<entry key="region" value = "europe"/>
</osgi:service-properties>
</osgi:service>
If you wanted to look this service up, you would use a filter attribute for the client. Here's how you
might specify the osgi:reference element to find this service as a client.
<osgi:reference id="greeterService" interface="com.apress.springenterpriserecipes.
osgi.helloworld.service.GreeterService"
filter="(region=europe)"
/>
There are also many standard attributes that the runtime configures for all services. For a good list,
consult http://www.osgi.org/javadoc/r2/org/osgi/framework/Constants.html . You may also use the
bean name of the original service as a predicate for finding a service. This will be very familiar.
Search WWH ::




Custom Search