This is because your bootstrap code is loading a different copy of the org.osgi.service.component package than that of the felix SCR implementation bundle inside the framework. I'm sure if your listener implemented AllServiceListener then you would see the events for the service, but you would still not be able to cast anything to the org.osgi.service.component package since there are two versions of this package floating around.
Code loaded outside of the framework (and booting the framework) will not be able to use the same packages as the bundles installed in the framework (except for the packages provided by the framework itself or the JVM). You may try setting the framework property to have the org.osgi.service.component exported by the system.bundle in an attempt to have the bundles in the framework use the same copy of the package as the boot strap code:
org.osgi.framework.system.packages.extra=org.osgi.service.component
But to be honest this is an approach I would avoid and instead I would try to install a third bundle that does the testing you need inside the framework.
Tom
----- Original message -----
From: Thomas Driessen via osgi-dev <osgi-dev@mail.osgi.org>
Sent by: osgi-dev-boun...@mail.osgi.org
To: "OSGi Developer Mail List" <osgi-dev@mail.osgi.org>
Cc:
Subject: [osgi-dev] No service events for an embedded OSGi Framework?
Date: Wed, Nov 28, 2018 7:11 AM
Hi,I'm trying to setup an OSGi framework instance (Felix) then to install two bundles and finally getting a reference to a ComponentFactory inside the framework via a ServiceListener. No Exceptions are thrown but my ServiceListener ist not getting any events.You can have a look at the code here:Or If you want to execute it and play with it you can run it here:just type the following commands into the terminal:cd benchmarksmvn clean installjava -jar target/benchmarks.jarI also tried to acquire the service directly by starting the bundles, then wait a second and then calling bundleContext.getServiceReference(ComponentFactory.class). But when I tried to turn this reference into a service viaComponentFactory<ITest> factory = bundleContext.getService(ref);I get a ClassCastException stating that Felix SCR's ComponentFactoryImplementation cannot be cast to ComponentFactory... which doesn't make much sense to me, as the ComponentFactoryImplementation implements ComponentFactory.Am I doing something fundamentally wrong?Kind regards,Thomas_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev