Hello Matt

I've finally chosen to use a simple ServiceListener on one of the
services that already uses my managed services. I register the main
service component itself as a listener with a filter on the needed
interface, and when an instance is registered, modified or
unregistered, it applies the required changes. This way my
implementation relying on a managed service factory and the services
consumer component that needs to be updated have no coupling.

Thanks for your answer. I don't use the service tracker, but in
another service, the multiple instances are simply collected with a
reference list (in blueprint), that is always updated when managed
services are created, modified or removed. This is more or less what a
tracker should do I think.

Thanks again.

Regards.


Le ven. 1 déc. 2023 à 16:37, Matt Pavlovich <[email protected]> a écrit :
>
> Hi Ephemeris-
>
> OSGi has several hooks you can use. Look into OSGi's EventHandler and 
> ServiceTracker
>
> Additionally, you can make another service that takes this service in as a 
> reference, then you get called when the service is added and removed.
>
> Look into OSGi component services, and bind/unbind hooks for references.
>
> Thanks,
> Matt Pavlovich
>
> > On Nov 30, 2023, at 2:19 AM, Ephemeris Lappis <[email protected]> 
> > wrote:
> >
> > Hello.
> >
> > To manage some kind of dynamic configuration, I've used a managed
> > service factory. It works as expected, and I can add, update or remove
> > instances deploying or undeploying files in the etc folder.
> >
> > The simple blueprint is like that :
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <blueprint
> > xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
> > xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0";
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
> > https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
> > http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
> > http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd";>
> >
> > <cm:managed-service-factory
> > factory-pid="com.together.ms"
> > interface="com.together.MyService">
> > <cm:managed-component 
> > class="com.together.component.MyServiceManagedComponent">
> > <cm:managed-properties
> > persistent-id=""
> > update-strategy="container-managed" />
> > </cm:managed-component>
> > </cm:managed-service-factory>
> > </blueprint>
> >
> > In another bundle, I'd like to know when an instance has been updated
> > or removed (new ones don't really matter). What's the best way to do
> > it, if possible ? Are there some kind of events and listeners to spy
> > managed services ?
> >
> > Thanks for your help.
> >
> > Regards.
>

Reply via email to