Thank you very much Felix. That works great.

Thanks again.
T

On Fri, May 21, 2010 at 12:55 PM, Felix Meschberger <[email protected]> wrote:
> Hi,
>
> On 21.05.2010 17:44, Tom Kesling wrote:
>> Thank for the feedback Angelo.
>>
>> I'm developing an application has config data managed externally.  The
>> config data represents components and their dependencies.  The
>> components are OSGI services and there are multiple service instances
>> (so that sets of components have their own instances).
>>
>> I have started with using DS and ComponentFactories.  The config is
>> turned into properties and then new components are created using
>> componentfactory.newInstance(properties).
>>
>> I was looking into the ConfigurationAdmin api and trying to understand
>> if/how I could use it to make this easier and write less code.  That
>> is when I discovered the ManagedServiceFactory.
>>
>> My understanding is that a ComponentFactory and a
>> ManagedServiceFactory can both be used to return multiple instances of
>> a service.
>>
>> The instances returned by the ManagedServiceFactory are associated
>> with a specific configuration instance and can be managed by
>> ConfigurationAdmin.  If I understand this correctly, I should be able
>> to create/update service instances via ConfigurationAdmin by
>> getting/creating the Configuration for a specific service instance and
>> calling the update method with the properties.  This seems like less
>> code and would be generic for any service type.  I'm uncertain if/how
>> I can define the service and it's dependencies via DS which is very
>> attractive.
>
> Declarative Services takes care of making the distinction.
>
> Consider a component (non-ComponentFactory, but either immediate,
> service or service factory) with name componentA.
>
> If there is a Configuration whose PID is "componentA", that
> configuration is provided to a single Component instance.
>
> If there exist one or more factory Configuration instances whose factory
> PID is "componentA", DS will create and activate one component instance
> for each factory configuration. Likewise if such a factory is deleted,
> DS will remove (deactivate and dispose) the respective component instance.
>
> So, if you want to have the user control component instances through
> factory configurations, declare your components to as usual and set the
> configuration-policy attribute to "required". This ensure that the
> component is only instantiated and created for existing factory
> configurations. If there is no factory configuration, there is no
> component instance.
>
>>
>> I'm uncertain how a ComponentFactory and their instances work with
>> ConfigurationAdmin and if the scenario above is possible.
>
> ComponentFactory instances are configured mainly with the configuration
> given to the newInstance method (apart from the default properties in
> the descriptor and the "global" configuration applying to all instances
> of the same ComponentFactory).
>
> Hope this helps.
>
> Regards
> Felix
>
>>
>> This is all new to me so I'm sure I'm missing things.
>>
>> Any advice on how to approach this is appreciated.
>>
>> Thanks,
>> T
>>
>>
>>
>>
>>
>> On Thu, May 20, 2010 at 4:44 PM, Angelo van der Sijpt
>> <[email protected]> wrote:
>>> It depends on what you need, and the mechanism you use for dependency 
>>> management. In short,
>>> - ManagedServiceFactory is a part of the Configuration Admin specification 
>>> from the Compendium (section 104). It allows you to create zero or more 
>>> services based on a configuration, in much the same way as you would 
>>> configure exactly one service using a ManagedService.
>>> - ComponentFactory is a part of the Declarative Services specification 
>>> (Compendium, 112), and is used for creating instances of a service 
>>> on-demand (see 112.2.4).
>>>
>>> If you need to generate services 'externally', for instance, you have a 
>>> service that discloses information based on some file system paths, you can 
>>> use a ManagedServiceFactory: you create a configuration for each of the 
>>> paths.
>>> If you need to be able to create a service for each 'getting' of the 
>>> service (so they don't get shared between components using the service), 
>>> and you happen to use SCR as a dependency management mechanism, you can go 
>>> with ComponentFactory.
>>>
>>> So, they are not necessarily comparable. What is your use case?
>>>
>>> Angelo
>>>
>>> On May 20, 2010, at 8:26 PM, Tom Kesling wrote:
>>>
>>>> Hello,
>>>> I'm trying to understand when to use a ManagedServiceFactory vs a
>>>> ComponentFactory.
>>>>
>>>> Any advice is appreciated.
>>>>
>>>> Thanks,
>>>> T
>>>> _______________________________________________
>>>> OSGi Developer Mail List
>>>> [email protected]
>>>> https://mail.osgi.org/mailman/listinfo/osgi-dev
>>>
>>>
>>> _______________________________________________
>>> OSGi Developer Mail List
>>> [email protected]
>>> https://mail.osgi.org/mailman/listinfo/osgi-dev
>>>
>>
>> _______________________________________________
>> OSGi Developer Mail List
>> [email protected]
>> https://mail.osgi.org/mailman/listinfo/osgi-dev
>>
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev
>

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to