SeamFramework.orgCommunity Documentation

Chapter 11. OSGi facilitation

11.1. Service registry
11.2. OSGi utilities
11.3. The registration

Weld-OSGi allows bean bundles to directly interact with the OSGi service registry by getting a ServiceRegistry bean:

@Inject ServiceRegistry registry;

This bean is injectable everywhere into a bean bundle.

It allows to:

Weld-OSGi allows to obtain, by injection into bean bundles, some of the useful objects of the OSGi environment:

It is possible to precise an external bundle by bundle symbolic name and version(optional)

@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") bundle;
@Inject @BundleName("com.sample.gui") bundle;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") BundleContext bundleContext;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") @BundleHeaders Map<String,String>metadata;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") @BundleHeader("Bundle-SymbolicName") String symbolicName;
@Inject @BundleName("com.sample.gui") @BundleVersion("4.2.1") @BundleDataFile("test.txt") File file;

If a BundleVersion annotation is provided without a BundleName annotation Weld-OSGi detects the problem and treats it as an error.

Weld-OSGi allows to obtain, by injection into bean bundles, Registration<T> of a specific type. A registration object represent all the bindings between a service contract class and its OSGi ServiceRegistration.

@Inject Registration<MyService> registrations;

It is possible to filter the obtained bindings by specifying OSGi LDAP properties and filter.

@Inject @AnyQualifier Registration<MyService> qualifiedRegistrations;
@Inject @Filter("(&(lang=EN)(country=US))") Registration<MyService> qualifiedRegistrations;

A Registration<T> allows to: