4

Is it possible to add declarative services using some kind of api?

A little background:

I have a server application based on dynamic scripts (they can be added, edited or removed at any time). Those scripts have dependencies to OSGi services and possibly each other. Whenever a script gets edited, the script gets compiled to javascript, and its dependencies are detected.

At that point, I'd like to (re)register it as a declarative service, so it will be activated / deactivated when its dependencies come and go.

  • Is this even possible? Or is there something major I'm missing?
  • If it isn't possible with an OSGi standard, is there a specific solution for Felix or Equinox?
  • Can you do that in the other frameworks, like iPojo or blueprint?
Frank Lee
  • 2,728
  • 19
  • 30
  • Are you sure you cannot use "normal" OSGi services? i.e. the lower level API - `BundleContext.registerService()` et al? – Dan Gravell Oct 21 '15 at 15:31
  • Yes, that is possible, but 'normal' OSGi services don't have the concept of dependencies to other services, so that would involve rebuilding a large part of DS. I ended up generating bundles, and installing / updating those, and letting DS deal with the rest. I did a talk about this at ApacheCon 2012: http://www.slideshare.net/FrankLyaruu/scripting-languages-in-osgi – Frank Lee Oct 22 '15 at 08:30

1 Answers1

6

There is no API to imperatively add declarative services. You can use the normal OSGi api to register and use services. Perhaps that is what you want?

You may want to checkout the Dependency Manager which may provide an API model giving you the dependency support you want.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
  • "There is no API to _imperatively_ add _declarative_ services." Wow! (My emphasis) However, it's not very difficult to envision such an API, is it? Could be quite powerful. – forty-two May 22 '12 at 20:29
  • If you want to do this, create a fragment for a bundle that holds the classes and add the DS XML to the fragment. It is quite easy to dynamically create such a simple JAR file since the manifest only requires a few lines of code. – Peter Kriens May 23 '12 at 06:23
  • Yeah, it does sound a bit like a paradox, doesn't it. @PeterKriens I've considered that, but the thing is, I'll have quite a lot of those services (2000+). To be able to add/remove them individually I'd need 2000+ bundles or fragments, and I have the feeling that that isn't a good idea. – Frank Lee May 23 '12 at 08:33
  • I'll have a look at the Felix Dependency Manager, and see where it leads me. I never understood its function, but it might be what I need. I'll post any interesting results here. As for using the regular service implementation, that will work, but then I'd need to 'roll my own' dependency manager. I guess I can do that, but I'm pretty sure the existing DS implementations are much better. – Frank Lee May 23 '12 at 08:42