Search code examples
osgiipojo

Access to service properties in service consumer ( iPOJO )


In iPOJO, is there any way to read service properties (e.g. getProperty(key) ) in service consumer? The publisher is pretty straight forward but, in consumer seems I can only use filter.

Thanks


Solution

  • You have to use callbacks to retrieve service properties:

    @Bind
    public void bindService(HelloService hello, Dictionary<String, Object> properties) {
          // ...
    }
    

    or

    @Bind
    public void bindService(HelloService hello, Map<String, Object> properties) {
      // ...
    }
    

    You can even retrieve the OSGi service registration:

    @Bind
    public void bindService(HelloService hello, ServiceReference<HelloService> reference) {
      // ...
    }
    

    All details are on http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html#note-about-callbacks