Search code examples
javaosgiapache-felixosgi-bundle

Rebind/restart bundles which depend on other one


UPDATED:

I will like to know if is possible to force all the dependencies which have reference to other OSGi Service to unbind to it, for then rebind.

e.g.

I have A, B, C all OSGi services which have a service dependency to X. Then X change something and wants that all other services which are binded to it execute unbind and then bind. This without X being stopped or reloaded or change the code of the other services.

Is this possible with standard OSGi?


Solution

  • You seem to be confusing service dependencies and package (type) dependencies.

    For service dependencies, when a service is unregistered and a replacement service registered, there are service events which are published. Clients of the service can react which is what Declarative Services, Blueprint and ServiceTracker all help with.

    For package dependencies, if a bundle which exports a package is updated, then all dependent bundles which import the package are left wired to the old version of the package. These dependent bundles can be refreshed which will caused them to be stopped, get new class loaders wired to the updated package, and started again. See https://osgi.org/javadoc/r5/core/org/osgi/framework/wiring/FrameworkWiring.html#refreshBundles%28java.util.Collection,%20org.osgi.framework.FrameworkListener...%29.