SeamFramework.orgCommunity Documentation

Chapter 9. Service auto publication and injection

9.1. Service bean and auto-published OSGi service description
9.2. OSGi service auto-publication with Publish annotation
9.2.1. Service type resolution
9.2.2. Service type blacklist
9.3. OSGiService annotated or Service<T> typed injection points
9.4. OSGiServiceBean and OSGiServiceProviderBean
9.5. Clearly specify a service implementation
9.5.1. Link between qualifiers and OSGi LDAP properties
9.5.2. Filter and Properties qualifiers
9.5.3. Filter and Properties stereotypes
9.5.4. Final LDAP filter
9.5.5. Using service filtering
9.6. Bean disambiguation and annotated type processing
9.6.1. Examples
9.6.2. Justification
9.7. Contextual services
9.7.1. OSGi service scopes
9.8. Required services
9.9. Inaccessible service at runtime

A Weld-OSGi auto-published service is described by these attributes (and their equivalents for a regular OSGi service):

A Weld-OSGi service bean is described by these attributes (and their equivalents for OSGi service lookup):

Annotate a CDI bean class with a Publish annotation makes Weld-OSGi register this bean as a OSGi service.

Such a service is accessible through Weld-OSGi service injection and OSGi classic mechanisms.

Automatically publish a new service implementation:

@Publish
public class MyServiceImpl implements MyService {
}

However, such an implementation also provides a regular CDI managed bean, so MyServiceImpl can also be injected using CDI within the bean bundle.

An OSGiService annotated or a Service<T> typed injection point is managed by Weld-OSGi through the creation of a new service bean. OSGiService annotation and Service<T> type are exclusive on injection point. If an injection point has both, Weld-OSGi detects the problem and treats it as an error.

OSGiService annotated or a Service<T> typed injection points are not eligible to regular CDI injection.

OSGiServiceBean injects an instance of the first service implementation matching the injection point.

OSGiServiceProviderBean injects a service provider (as a Service<T>) for all the service implementations matching the injection point.

Service provider allows to over-specify the matching service implementation set with additional OSGi service properties.

Service provider does not allow to subtype the matching service implementation set.

Service provider allows to instantiate the first service implementation matching the (possibly) over-specified injection point.

Service implementation are searched into the OSGi service registry, it may be:

Qualifier annotations might be used for both specifying auto-published services and service injection points. Such qualifiers should be seen as OSGi service properties, thus every set of qualifiers corresponds to a set of OSGi service properties and so to a OSGi service LDAP filter.

However qualifiers keep a regular meaning for the CDI generated bean of an auto-published service class.

A qualifier will generate an OSGi service property for each of its valued element (an element with a default value is always considered valued) following these rules:

Weld-OSGi ensures that every OSGiService annotated or Service<T> typed injection point matches an unique OSGiServiceBean or OSGiServiceProviderBean.

Therefore, for every bean bundle Weld-OSGi:

OSGiService annotated injection points are wrapped as:

@Inject @OSGiService @Filter(Calculated_filter) Type var_name;

The global OSGi LDAP filter of the final Filter qualifier is calculated from:

An auto-published service instance is a CDI contextual instance, so:

It is discouraged to use regular OSGi service publication mechanisms in a Weld-OSGi application.

A OSGiService annotated or Service<T> typed injection point might be annotated Required

OSGiServiceBean and OSGiServiceProviderBeans bean instances are dynamically obtained as OSGi service instance.

No instance might be available at runtime due to OSGi dynamism, in such case a OSGiServiceUnavailableException is thrown with any OSGiServiceBean method call or the OSGiServiceProviderBeans get method call.