Ask Your Question
0

ServiceHelper.getInstance (IAClass.class,containerName, this) -- returns null ?,How to check if a Interface Instance properly configured to the OSGI Registery ?

asked 2014-11-09 17:31:48 -0700

esumit gravatar image

Question :How to check if a Interface Instance properly configured to the OSGI Resgitery ?, How we can debug it if that has not happened successfully ?

As in one of my implementation case - ServiceHelper.getInstance (IAClass.class,containerName, this) -- returns null ? However similar other implementation return the instance.

{ I have checked everything e.g. pom.xml, versions, .m2 etc , most trivial stuff, seems now I need to debug more on the Service Registry side. }

Explanation

Point-1

Please refer Topology.java : that calls the instance of ISwitchManager.class, and then uses its one of the interface to access its functionl

ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); if (switchManager == null) { return null; }

Point-2:

I have created two OSGI Module ,and followed the proper approach as defined everywhere e.g. pom.xml,dependencies

1.IXManager (api and implementation)
2.IXManager (api and implementation)

so I can use like the above 1 and 2 in same file:

IXManager xManager = (IXManager) ServiceHelper .getInstance(IXManager.class, containerName, this);

if (xManager == null) { return null; } xManager return the instance and everything works.

IYManager yManager = (IYManager) ServiceHelper .getInstance(IYManager.class, containerName, this); if (yManager == null) { return null; }

yManager returns null :

Here is how I wrote the activator example classes :

package org.opendaylight.controller.xmanager.internal;

import org.apache.felix.dm.Component; mport org.opendaylight.controller.xmanager.IXManager; import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; import org.slf4j.Logger; import org.slf4j.LoggerFactory;

/** * Bundle Activator for XManager class */ public class Activator extends ComponentActivatorAbstractBase { protected static final Logger logger = LoggerFactory.getLogger(Activator.class);

@Override
public Object[] getImplementations() {
    Object[] res = { XManager.class };
    return res;
}

@Override
public void configureInstance(Component c, Object imp, String containerName) {
    if (imp.equals(XManager .class)) {

        String interfaces[] = new String[] {IXManager.class.getName()};
        c.setInterface(interfaces, null);
    }
}

}

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-11-11 11:12:44 -0700

jgoodyear gravatar image

In Helium console you can look for exported packages in the container.

Couple of useful commands: http://karaf.apache.org/manual/latest/commands/bundle-services.html http://karaf.apache.org/manual/latest/commands/bundle-capabilities.html http://karaf.apache.org/manual/latest/commands/service-list.html

edit flag offensive delete publish link more
0

answered 2014-11-10 01:30:13 -0700

esumit gravatar image

On OSGI Consol I typed the following command :

OSGI>> b bundle_id

that gave a lot of information including the "Registered Services" e.g. {org.opendaylight.controller.sal.core.IContainerAware}={service.id=75}

This information helped me to compare with other existing services and from that I found the issue e.g. this information told that requisite service didn't get register to the intended bundle.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2014-11-09 17:31:48 -0700

Seen: 990 times

Last updated: Nov 11 '14