Re: [osgi-dev] No service events for an embedded OSGi Framework?
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 Sent by: osgi-dev-boun...@mail.osgi.orgTo: "OSGi Developer Mail List" 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: https://github.com/Sandared/jmh-benchmarks/blob/master/benchmarks/src/main/java/io/jatoms/jmh/OSGiBenchmark2.java Or If you want to execute it and play with it you can run it here: https://gitpod.io/#https://github.com/Sandared/jmh-benchmarks/blob/master/benchmarks/src/main/java/io/jatoms/jmh/OSGiBenchmark2.java just type the following commands into the terminal: cd benchmarks mvn clean install java -jar target/benchmarks.jar I 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 via ComponentFactory 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 Listosgi-dev@mail.osgi.orghttps://mail.osgi.org/mailman/listinfo/osgi-dev ___ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev
Re: [osgi-dev] No service events for an embedded OSGi Framework?
My guess is that you are trying to start a framework from inside a framework, and then the code outside is using a different view of the ComponentFactory interface from the code inside. Normally you would need to use a system packages extra property when launching the inner framework (to share the package from outside to inside), or use reflection to access the service instance. Best Regards, Tim Sent from my iPhone > On 28 Nov 2018, at 13:11, Thomas Driessen via osgi-dev > wrote: > > 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: > https://github.com/Sandared/jmh-benchmarks/blob/master/benchmarks/src/main/java/io/jatoms/jmh/OSGiBenchmark2.java > > Or If you want to execute it and play with it you can run it here: > https://gitpod.io/#https://github.com/Sandared/jmh-benchmarks/blob/master/benchmarks/src/main/java/io/jatoms/jmh/OSGiBenchmark2.java > > just type the following commands into the terminal: > cd benchmarks > mvn clean install > java -jar target/benchmarks.jar > > I 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 via > > ComponentFactory 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
[osgi-dev] No service events for an embedded OSGi Framework?
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: https://github.com/Sandared/jmh-benchmarks/blob/master/benchmarks/src/main/java/io/jatoms/jmh/OSGiBenchmark2.java Or If you want to execute it and play with it you can run it here: https://gitpod.io/#https://github.com/Sandared/jmh-benchmarks/blob/master/benchmarks/src/main/java/io/jatoms/jmh/OSGiBenchmark2.java just type the following commands into the terminal: cd benchmarks mvn clean install java -jar target/benchmarks.jar I 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 via ComponentFactory 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