Hi,
Apologies in advance if this is stupid beginners question. I have searched the
web and consulted my "OSGIi in Action", but to no avail.
I have a simple service bundle, and I want to track the availability of that
service i another bundle. Sounds pretty basic. For some reason I get a
reference to the implementation object instead of a ref to the interface when
ServiceTrackerCustomizer.addingService() is called. No big deal, but when I try
to cast that ref back to the interface a ClassCastException is thrown.
I have a faint feeling that this has something to do with class loaders, but I
cannot pinpoint the real issue.
In the Activator of the service bundle:
private MyService myService; // Interface for MyServiceImpl
public final void start(BundleContext bundleContext) {
context = bundleContext;
myService = new MyServiceImpl();
context.registerService(MyService.class.getName(), myService, null);
}
Only the package with the MyService interface is exported.
In the class that implements the ServiceTrackerCustomizer:
public Object addingService(ServiceReference reference) {
MyService myService = (MyService)context.getService(reference); //
throws ClassCastException. reference is of type MyClassImpl
...
}
This bundle only imports the package with MyService.
Thanks for your attention.
Your help is greatly appreciated.
Kind Regards,
Erwin_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev