1
votes

Suppose there are two OSGi bundle's A and B exporting x and y package respectively. If there is a case where A is dependent on B's export and B on A's export which one should be started first. And suppose one wants to get the ServiceReference from shared registry in a different class(i.e. not in Activator class) then how to initialize the BundleContext object with the current bundle's context.

This might solve the case I mentioned above, about interdependency. Like A can use B's export in its start method of activator and B can use A's export in a different class's method when invoked

1
If A depends on B and B depends on A, can you start the two bundles? For bundlecontext I think we have a BundleContextAware interfaceLinh Nguyen
BundleContext bundleContext = FrameworkUtil.getBundle(JasperService.class).getBundleContext(); ServiceReference<?> empServiceReference = bundleContext.getServiceReference(yourclassname.class.getName());Nilesh
This works just fine for getting the bundlecontext of current bundle in a class other than activator.Nilesh

1 Answers

2
votes

Package resolution (resolving) is different that starting and running bundles. It is very important not to conflate the two.

An OSGi framework can resolve cycles in package dependencies. So once the bundles are resolved, they can be started in some order. You need to make sure you don't design bundles to depend upon their relative start order. Which is why you use services and something like DS. Cycles in service dependencies can't be solved. So make sure you avoid such cycles.