This project has retired. For details please refer to its Attic page.
OSGi
Qi4j
Introduction
Tutorials
Javadoc
Samples
Core
Libraries
Extensions
Tools
Glossary 

OSGi

code

docs

tests

OSGi Library allows you to import OSGi services as Qi4j Services and to export Qi4j Services as OSGi Services both leveraging the Qi4j Availability and OSGi FallbackStrategy mechanisms.

Table 37. Artifact

Group IDArtifact IDVersion

org.qi4j.library

org.qi4j.library.osgi

2.0


Export Qi4j services to an OSGi Bundle

interface MyQi4jService
    extends OSGiEnabledService
{
    // ...
}
  [...snip...]

public void assemble( ModuleAssembly module )
    throws AssemblyException
{
    BundleContext bundleContext = // ...
      [...snip...]

    module.services( OSGiServiceExporter.class ).
        setMetaInfo( bundleContext );
    module.services( MyQi4jService.class );
}

Import OSGi services in a Qi4j Module

public void assemble( ModuleAssembly module )
    throws AssemblyException
{
  [...snip...]

    module.services( OSGiServiceImporter.class ).
        setMetaInfo( new OSGiImportInfo( bundleContext,
                                         MyOSGiService.class,
                                         MyOtherOSGiService.class ) ).
        setMetaInfo( new MyFallbackStrategy() );
}

The fallback strategy is invoked when the OSGi service is not available and a method call is invoked.