Actually what isn’t clear to me is getting the Service. The problem is, is that if I try to actually get the service via
ServiceReference<MyClass> ref = bundleContext.getServiceReference(MyClass.class) and then bundleContext.getService(ref) it will give me a ClassCastException. Actually my Service should be defined in an external Jar which the Bundle implements. The Service Dependency is then included in the Main Application and the Main Application should have access to the Felix Service, is this even Possible? Beste Grüße / Best Regards Christian Schmitt Entwickler / Developer > Am 19.07.2016 um 11:25 schrieb Christian Schmitt <[email protected]>: > > Hello, > > currently I’m looking forward to use Apache Felix inside a already working > application as a Extension mechanism. > Apache Felix should be embedded into the Main Application. > > Actually I tried to look at: > > http://svn.apache.org/repos/asf/felix/trunk/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/ > > <http://svn.apache.org/repos/asf/felix/trunk/examples/servicebased.host/src/main/java/org/apache/felix/example/servicebased/host/launch/> > > However all these examples under examples are for Apache Felix 4.0. > > But I guess after adding the correct OSGi packages it should work for 5.4, > too. > > However now my Question, currently my application code is something like > that, scala: > > def createFramework(config: Map[String, String]): Framework = { > val factoryLoader = ServiceLoader.load(classOf[FrameworkFactory]) > val data = for (factory <- factoryLoader.iterator().asScala.toList) yield > factory.newFramework(config.asJava) > data.headOption.getOrElse(throw new IllegalStateException("Unable to load > FrameworkFactory service.")) > } > > val config = Map( > Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA -> > "org.apache.felix.example.servicebased.host.service; version=1.0.0" > ) > val framework = createFramework(config) > framework.init() > framework.start() > > val bundleContext = framework.getBundleContext > val activator = new Activator() > activator.start(bundleContext) > > > applicationLifecycle.addStopHook(() => Future { > framework.waitForStop(0) > }) > > Now I want to upload a bundle via HTTP and register it / start it. > Is the only thing I need to do now expose the bundleContext so that I can use > it somewhere else, and then > upload the bundle to a well known path and call > > bundleContext.installBundle(wellKnownPath) > bundle.start() > > ? > > The next thing is stopping? > There is a well known method called bundleContext.getBundle(id int) where do > I retrieve the bundle ID? > I guess I could just use bundleContext.getBundle(String location) again. > > Next is register a service/thing and retrieve it? > If I have a bundle that defines serviceX and another bundle that defines > serviceX and start both, does this give an exception or how do I know which > service is correct and especially how to retrieve register them? > > Do I need to call bundleContext.registerService(…) > before I install the bundles? > > Somehow that is not exactly clear to me on how my application can then get a > Service from Felix to do something useful. > > > Beste Grüße / Best Regards > > Christian Schmitt > Entwickler / Developer >
smime.p7s
Description: S/MIME cryptographic signature

