Hi,

Am 31.01.2012 um 09:40 schrieb Peter Gardfjäll:

> To my question:
> 
> I have a ManagedFactoryService that creates service instances and I have
> another (client) bundle that creates instances by registering new
> configurations with the factory.
> What I currently find difficult is to propagate errors (such as a required
> configuration property missing) from the ManagedFactoryService to the
> client.
> 
> When the client uses an invalid configuration dictionary to instantiate a
> new service instance as follows
> 
>        // instantiate new service with serviceConfig as instantiation
> parameters
>        Configuration config =
> configurationAdmin.createFactoryConfiguration(factoryPid, null);
>        config.update(serviceConfig);
> 
> no exception is raised despite the ManagedFactoryService throwing a
> ConfigurationException.
> I guess this is expected since configuration updates are handled on a
> separate thread of execution.
> But this is problematic since, from the client bundle's perspective, the
> configuration update appears to have been successful.
> 
> So what I really need to know is if there is a best practice for
> propagating the configuration error from the ManagedFactoryService to the
> client?
> Any suggestions would be appreciated.

Yes, this might be perceived as a problem. But this is how decoupling works.

If you want to have tight coupling between the configuration producer (client 
you say) and the service producer (ManagedServiceFactory in your case) then you 
have to do close coupling: Create a factory which is fed by the client with 
configuration, checks this configuration and then does the rest.

For example: Provide a service where clients can send configuration. Ther 
service checks the configuration and fails if the configuration is bad. 
Otherwise the service creates the FactoryConfiguration on behalf of the client 
and thus causes the ManagedServiceFactory to be put in action.

One way of doing this might be leveraging Declarative Services ComponentFactory 
components. These expose a ComponentFactory service with a newInstance method 
taking a Dictionary object. If the creation instances fails due to wrong 
configuration you get direct feedback by getting an Exception.

Hope this helps.

Regards
Felix
> 
> best regards, Peter
> 
> 
> [1] -
> http://karaf.922171.n3.nabble.com/Best-practice-on-propagating-configuration-errors-from-ManagedFactoryService-to-client-tp3699427p3699427.html


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to