Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

configuration - OSGi Declarative Services vs. ManagedService for configuring service?

I just recently stumbled upon the fact that Declarative Services in OSGi can set the configuration of a component to required so that the component receives it upon activation, removing the gap between component activation and configuration. I also realized with this that you can receive configuration updates via the modified-method.

It seems to me like this functionality is quite similar to that provided by implementing the ManagedService interface and publishing that as one of the "services" you provide.

It seems like I could completely ignore ManagedService & just use the DS configuration injection.

Is one of these techniques preferred over the other or are there other trade-offs that I'm not seeing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, you can completely ignore ManagedService and ManagedServiceFactory and just use Declarative Services components. And yes I would recommend this approach.

Just think of this as different levels of abstraction. MS/MSF is the low-level API for config admin, and it is available even when you don't have a DS bundle running. The advantage of this is you can write configurable services without having a dependency on DS, which may be desirable for certain "system level" components.

However, if you are happy to depend on DS, e.g. for "application level" components, then using DS's built-in integration with config admin will make your life a lot easier.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...