Service Trackers for OSGi Services

In an OSGi runtime ecosystem, you must consider how your apps can rely on OSGi services in other modules for functionality. It’s possible for service implementations to be swapped out or removed entirely, and your app must not just survive but thrive in this environment.

If you want to call OSGi services from an OSGi Declarative Services @Component classes, it’s easy: you just use a Declarative Services (DS) annotation, @Reference, to inject the service. The component activates when the referenced service is available.

If you want to call an OSGi service from a bean, use OSGi CDI integration.

DS @Reference with @Components and OSGi CDI integration with beans manage much of the complexity of service dynamism for you transparently. If you can use either of them, you should. Otherwise, read implement a Service Tracker to look up services in the service registry.

« Using OSGi Services in a BeanUsing a Service Tracker »
0 人中有 0 人觉得有帮助