Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • A bind method called when a service appears
  • An unbind method called when a service disappears
    Moreover, callbacks can be in the component super class (in this case methods must be public).
    These methods can have

...

  • four signatures:
  • Without any argument: the method is just a notification
  • With an object of the required service object : the object is the implicated service object
  • With an OSGi service reference: the service reference appearing or disappearing
  • With the service object and the OSGi service reference

The following component shows an example of implementation using this mechanism:

...

  • Dynamic policy (default) : the binding are managed dynamically. At each injection, the same provider is injected if the provider is always available. Else a new one is chosen. For aggregate dependency, the array order does not change, new providers are placed at the end of the array.
  • Static policy : the binding is static. So, once bound a provider cannot disappear. If it disappears, the instance is invalidated and cannot be revalidated without stopping and restarting the instance.
  • Dynamic-priority policy : the binding is managed dynamically but the injected provider is selected by using the OSGi ranking policy. Two injections can return two different providers, is a new provider is 'better' than the previous one, despite the first one is alway available. For aggregate dependency, the array is sorted.

A static binding is declared as following :

Code Block

<component classname="...HelloConsumer">
<requires field="m_hellos" policy="static"/>
...
</component>

A dynamic-priority binding is declared as following :

Code Block

<component classname="...HelloConsumer">
<requires field="m_hellos" policy="dynamic-priority"/>
...
</component>

Requires Metadata

A requires element metadata can contains :

...