I have been working with OSGi for a few months and recently started
learning about and implementing configuration management with with
declarative services. I have created a Component Factory following the
Multiton method following the example at
http://wiki.osgi.org/wiki/Declarative_Services.

Using Apache Web Console I have confirmed that when I create a new
component with String instancePid =
configAdmin.createFactoryConfiguration(factoryPid, null) the new instance
shows up in the console and is registered under the appropriate interface.

I have a ServiceListener listening for service registration. Below is and
example of the serviceChanged method I have implemented. I get the
component ServiceReference but when I try to get the interface from
BundleContext it is always null.

public void serviceChanged(ServiceEvent event)
{
   ServiceReference ref = event.getServiceReference();
   Object sid = ref.getProperty(Constants.SERVICE_PID);
   if(sid != null && sid instanceof String && ( (String)sid
).equals(instancePid ) )
   {
      if(event.getType() == ServiceEvent.REGISTERED)
      {
          MyInterface interface =
(MyInterface)bundleContext.getService(ref);
       >>>> I make it here but interface is always null.
      }
   }
}

As an alternate approach I tried utilizing a service tracker for
MyInterface and addService calls are received, but the incoming interface
is again always null.

I confirmed that the bundle (where I am get the bundle context from) is
ACTIVE. I checked ServiceReference.isAssignableTo on my bundle and
MyInterface.class.getName() and it returns true.

I have dealt with singleton services and never had a problem getting
MyInterface using the above approach. Is there something different about
how components from a component factory get registered using DS?

I use the equinox implementation of ogsi, DS, and CM with BND.

I suspect that I'm missing something fundamental, or got my wires crossed
on utilizing factories versus services, but I can't quite see where the
problem is. Any guidance is appreciated.

Thanks,
Shawn

















_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to