Sharing custom service between bundles

asked 2016-06-01 07:39:04 -0800

medvedmike gravatar image

updated 2016-06-01 07:43:35 -0800

I trying to create my own service and share it between two bundles but have some problems. There are two bundles A and B. Service interface defined in bundle A. Bundle B implements service and define it in own yang model and in xml configuration. Bundle A starts first. I want to detect moment when bundle B starts and get service from it in bundle A. In bundle A module factory there is subscription for bundle events and moment of loading B detecting fine. But in provided services list there is no target service interface (only odl ModuleFactory)

Bundle A service interface:

public interface SomeCustomService  {/*...*/}

Bundle A yang module:

identity some-custom-service {
    base "config:service-type";
    config:java-class "";
identity a-impl {
    base config:module-type;
    config:java-name-prefix A;

Bundle B service implementation:

public class SomeCustomServiceImpl implements SomeCustomService, AutoCloseable { /*...*/ }

Bundle B yang module:

identity b-identity {
    base config:module-type;
    config:provided-service a-prefix:some-custom-service;
    config:java-name-prefix B;

Bundle B configuration:

        <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
            <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
                    <type xmlns:prefix="urn:b-module">prefix:a-module</type>
            <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
                    <type xmlns:a="urn:a-module">a:some-custom-service</type>


Bundle A module factory implementation:

public class AModuleFactory extends {

    private BundleListener bundleListener = event -> {
        try {
            switch (event.getType()) {
                case BundleEvent.STARTED:
          "Bundle {} started", event.getBundle().getSymbolicName());
        } catch (Exception e) {
            log.warn("Notification handling error", e);

    public AModule instantiateModule(String instanceName, DependencyResolver dependencyResolver,
                                                    BundleContext bundleContext) {
        AModule module = super.instantiateModule(instanceName, dependencyResolver, bundleContext);
        return module;

In case BundleEvent.STARTED: case label call of method event.getBundle().getRegisteredServices() return array with only one service interface ModuleFactory instead both ModuleFactory and SomeCustomService.

edit retag flag offensive close merge delete


Does anyone have any ideas?

medvedmike ( 2016-06-02 00:33:01 -0800 )edit