Dynamically wire OSGi Services by configuration properties

I am currently facing a problem of how to dynamically "wire" OSGi Services depending on their configuration properties. I want to do that with Declarative Services.

To give a concrete example: I have two different OSGi Services A and B which both are ManagedServiceFactories and require configuration. So I can have multiple instances of A and multiple instances of B each with separate configurations.

I use Felix FileInstall, DS/SCR and BNDTools and my configs look like this (simplified):

a-one.cfg: b.id = foo

a-two.cfg: b.id = bar

b-one.cfg: id = foo

b-two.cfg: id = bar

Now I want to wire/bind service b-one to a-one and service b-two to a-two (depending on their matching configuration properties b.id = id).

Currently I can see two approaches on how to achieve this:

  1. Bind all available instances of Service B to the instances of Service A and select the proper Service B depending on its id.
  2. Implement an own ManagedServiceFactory for Service A which creates an LDAP filter to find the proper instance of Service B.

For solution 1.) I do not like that I need to bind all instances of Service B to every instance of Service A. I like to only bind the instance of Service B which meets my configuration property constraint.

For solution 2.) I do not like that I need to dig to the lower levels: own ManagedServiceFactory and bypassing DS by manually find the proper (LDAP filtered) Service instance.

Do anyone know a better solution or "best practice" how to achieve that? I am not sure if maybe the WireAdmin spec can help me here?

Solution with BNDTools/BND Annotation would be welcomed ;)

tia

Cheers Sascha

-------------Problems Reply------------

DS always puts all configuration information as service properties if it registers a service for a Component. You should do the same in your A and B ManagedServiceFactory so the services will be searchable.

On the other hand, if you specify a property for your reference with the ".target" suffix, you can specify via configuration which service to pick up.

With your example:

  • You create a component for B
  • You specify a reference in component B for services A with the name a
  • You specify a property in component B with the name a.target
  • You configure a.target with LDAP search filters. If you do not specify a value for this property, a random A service will be picked up
Category:java Views:3 Time:2019-01-07

Related post

  • Can IIS-hosted WCF service be configured for BOTH Windows Auth and Anonymous? 2009-06-10

    I've got a small WCF webservice working with the built-in WCF Service Host and with hosting by the Visual Studio 2008 built-in development webserver. I these hosting enviroments I have relied on the WCF Test Client for invoking the service methods. N

  • Dynamically create and configure OSGi Services with dependencies 2010-07-18

    In my current application i want to create and configure osgi services at runtime through a user interface. I've looked into the OSGi Metatype specification but it only supports simple type attributes. So my questions are: Is there a good reason why

  • How to configure Spring-DM OSGi service for new instance per call? 2010-06-16

    I'm starting to delve into using Spring DM and OSGi services in an RCP application. I've created a service which is used by another bundle in the RCP application. It does a lookup of the service via calls to getBundleContext().getServiceReference() u

  • How can I filter OSGi service visibility? 2009-05-15

    OSGi employs a service-oriented architecture: Bundles register service objects, that other bundles consume. Service publishing and binding is managed by the framework. This decouples service providers from service users completely (except for the nee

  • There is a GUI to manage OSGi services? (in Eclipse or another project) 2011-05-30

    I'm working with an application that uses and manages a large amount of OSGi services and implementations for each service, with properties, dynamism and so. Using the command line of the Equinox console is useful, with commands like services or list

  • Do published OSGI services need to have their packages exported? 2012-01-09

    Do the packages that contain OSGI services need to be exported in order to publish to the service registry? Or does publishing to the service registry get round the need to export the package? --------------Solutions------------- Short answers; 1st q

  • Message bus for OSGi services 2012-01-29

    I'm in the middle of a project where we will migrate a major software system based on a larger set of custom made technologies to be based on OSGi services. For this we will likely need a some sort of message bus that plays nice with OSGi services. S

  • How to auto-start/eager start OSGi services on Eclipse platform 2012-03-12

    I develop an Eclipse RCP application which makes heavy use of OSGi bundles which provide services for later use. The use case requires the bundles to register their services (e.g. import filters) to be used later on in different situations. The OSGi

  • OSGi services architecture: creation of service at request of consumer 2012-03-28

    I am developing an application in Eclipse RCP. I need help with a design decision concerning the design of a service. I have some bundles which are used to provide an REngine object to other modules. The REngine is an interface to a calculation engin

  • Java OSGi Centralised Network Configuration 2009-09-01

    I'm looking to create an app based on the OSGi model. One of the elements of this will be network access (http and obr initially) I am looking for a way of centralising the network config (proxying, encryption, etc) perhaps to a single bundle that th

  • Prioritizing OSGi service selection within a container when more than one implementation exist 2009-12-05

    I am playing with OSGi and have a few bundles. Bundle A and B both contain a registered service which implement a single interface. The third bundle C includes code to lookup a service implementing the previously mentioned interface. The A and B bund

  • Maven: Unresolved references to [org.osgi.service.http] 2010-03-27

    I'm trying to create a bundle using HttpService for register Servlet using maven-bundle-plugin. The pom.xml of the project is: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocat

  • Why should I prefer OSGi Services over exported packages? 2010-05-05

    I am trying to get my head around OSGi Services. The main question I keep asking myself is: What's the benefit of using services instead of working with bundles and their exported packages? As far as I know it seems the concept of Late Binding has so

  • How to construct an OSGi service with dependencies and publish via DS 2010-07-05

    My sample classes: public class MyModel implements Model { : : } public class SingleModelProvider implements ModelProvider { public SingleModelProvider(Model providedModel, List actions) { : } } The plan is to reuse the SingleModelProvider class in s

  • How to choose in runtime among several OSGi services in an intelligent way? 2011-04-27

    I've in mind an intelligent system which can choose among available OSGi services dynamically. That is, choose an implementation or another depending of some runtime parameter. For example, notify to a running algorithm that change an operator after

  • Eclipse on macosx: org.osgi.service.application.ApplicationException: No application id has been found 2011-07-05

    I had a problem on my macbook pro and a fresh installation of eclipse. I would like to share the solution I got after some hours of puzzling. Problem: Starting eclipse Helios does not work. A pop up window appears and suggests to look into the log fi

  • org.osgi.service.application.ApplicationException: No application id has been found 2011-09-13

    !ENTRY org.eclipse.osgi 4 0 2011-09-13 10:30:39.110 !MESSAGE Application error !STACK 1 org.osgi.service.application.ApplicationException: No application id has been found. at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(Eclip

  • multiple OSGi service instances and DS binding 2012-03-11

    I think I'm on the right track using OSGi services + DS together, however, I really feel like abusing it. Either that, or it's just pure awesome. (Both is still possible). So let's imagine the following application: it's a house database. I have two

  • Integrating Guice and OSGi services 2012-04-12

    What's the current situation with integrating Guice and OSGi? I.e. exposing OSGi services from Guice, injecting them, etc. Peaberry's main page mentions "The Guice trunk (which will become 2.0)", but 1.2 seems up-to-date, since it fixes http://code.g

  • Exporting Spring components as OSGi services 2012-04-13

    Is it possible to automatically register a Spring @Component (or one of its specifications; e.g. @Repository) as an OSGi service? So I can use autowiring and all other benefits of Spring inside one bundle and OSGi Service Registry to communicate betw

  • OSGi service reference is null (service from launcher to bundle) 2014-04-09

    I need to pass some parameters from felix launcher class (Main) to bundle and I followed this advice. What I did Launcher project test.launcher package contains:Main.java,Temp.java,TempI.java Bundle project test.bundle package contains:Activator.java

  • OSGi Service wrapping a jar 2009-04-18

    I am trying to create an OSGi service that wraps another jar. I added the jar to the project, the classpath and the binary build. I registered the service in the Activator but when the consuming bundle calls the service I get a java.lang.NoClassDefFo

  • Working example for a remote OSGI service 2009-08-31

    I am new to programming with OSGI. Can anyone provide me a working example of a client/server osgi service invocation. I have been trying to acheve this for the last 2 weeks without any success. My service is being discovered and executed by an eclip

  • Immutable types as configuration properties 2009-09-18

    Is it possible to use immutable types as configuration properties with .NET's configuration API? Let's say I have an immutable type called MyClass: public class ImmutableClass { private readonly int value; public ImmutableClass(int value) { this.valu

  • Dynamically call web service! 2009-12-28

    I need to dynamically call web service! For this I made simple web service Service1.asmx Then I created the proxy class for the Service1 Web Service, I use the WSDL.exe utility and following command at the command prompt: wsdl /language:VB /out:mycla

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.133 (s). 11 q(s)