0

Let's say I have an OSGi service A, declared using DS and metatype configuration.

Then let's call B another service which is tracking any object based on a property filter, which does not belong to A's configuration.

Is there any possibility, in A, to access the service properties and update them at runtime, so that B will notice the change?

Note that the property tracked by B is not a configuration one, but it's something that A can deduce from its own configuration, so ideally A would update its service properties in its @Activate method after parsing the configuration.

cyberz
  • 884
  • 1
  • 8
  • 16

2 Answers2

1

If you do not care about the direct coupling of the config syntax to the property then there is a much simpler solution.

Simply set the service property in the configuration of component A. It will be directly reflected as a service property that B can then filter on.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
0

You can register the service programmatically in the Activate method of A so you can decide what service properties should be added.

Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
  • Wouldn't A be registered twice then? – cyberz Jul 03 '16 at 17:46
  • @cyberz No, you just have to make sure that your component does not directly implement the service interface. – Neil Bartlett Jul 04 '16 at 00:03
  • If you do not specify that the component should register an OSGi service automatically, it won't be registered twice. Normally it means that you should not use the @Service annotation. – Balazs Zsoldos Jul 04 '16 at 08:08
  • @Peter Kriens Depending on what annotation set is used. If Felix SCR annotations are used, then it is the _@Service_ annotation that forces the annotation processor to generate the service element in the XML. I guess bnd uses the annotations from the spec, but I am not familiar with those. – Balazs Zsoldos Jul 04 '16 at 12:38
  • We've standardized the annotations in the OSGi and they are no longer bnd's. Since the Felix guys (well Adobe) was part of this work I assume the Felix SCR annotations are now more or less deprecated. I think we should try to use the standard here to not confuse newcomers. – Peter Kriens Jul 05 '16 at 09:22
  • @PeterKriens Well, I neither use SCR nor the Spec annotations nowadays. However, do you think SCR guys know that their annotations are deprecated? They released version 1.10.0 of their bundle less than a month ago :). – Balazs Zsoldos Jul 05 '16 at 10:10
  • That is why I used 'more or less'. Beats me why anybody wants to suffer through non-standard annotations, we deprecated the bnd annotations now to minimize fragmentations. Then again, it is a free world :-) – Peter Kriens Jul 12 '16 at 09:52