Hi guys,
My question is for each of the service objects created by
ServiceFactory, how can their separate configuration be managed through
ManagedServiceFactory or are they suppose to be configured through
ManagedService?
After reading the spec on ManagedServiceFactory, my feeling is that if
we use it, we dont use ServiceFactory to create services but
ManagedServiceFactory will create services and registers them instead,
since the lifecycle of managing the services seems to be part of the
ManagedServiceFactory interface.
So say for instance, I want to create different service instance of
JdoService, each configured to connect into different databases. What's
the right way of doing this? Use ServiceFactory or ManagedServiceFactory
(which then will be created via ConfigurationAdmin.createFactory()
method)? My own understanding seems to lead me to using
ManagedServiceFactory instead of ServiceFactory.
Just wondering if my understanding is correct. Below is a sample of what
I think the implementation of ManagedServiceFactory will look like.
Makas
public class JdoServiceConfigurationFactory implements
ManagedServiceFactory
{
private Map<String, ServiceWrapper> m_ServiceRegistrations;
private BundleContext m_Context;
public JdoServiceConfigurationFactory( BundleContext context )
{
m_Context = context;
m_ServiceRegistrations = new HashMap<String, ServiceWrapper>();
}
public String getName()
{
return "Jdo Service Factory";
}
public void updated( String pid, Dictionary properties ) throws
ConfigurationException
{
ServiceWrapper sw = m_ServiceRegistrations.get( pid );
if( sw != null )
{
IJdoService service = sw.service;
ServiceRegistration sr = sw.serviceRegistration;
String userName = (String) properties.get( "user.name" );
String password = (String) properties.get ( "password" );
String url = (String) properties.get( "url" );
service.update( userName, password, url );
// Update the ServiceRegistration.
sr.setProperties( properties );
}
else
{
IJdoService service = new JdoService( properties );
ServiceRegistration sr = m_Context.registerService(
IJdoService.class.getName(), service, properties );
sw = new ServiceWrapper( sr, service );
m_ServiceRegistrations.put( pid, sw );
}
}
public void deleted( String pid )
{
ServiceWrapper sw = m_ServiceRegistrations.remove( pid );
if( sw != null )
{
sw.serviceRegistration.unregister();
sw.service = null;
sw.serviceRegistration = null;
}
}
private static final class ServiceWrapper
{
ServiceRegistration serviceRegistration;
IJdoService service;
public ServiceWrapper( ServiceRegistration
serviceRegistration, IJdoService service )
{
this.serviceRegistration = serviceRegistration;
this.service = service;
}
}
}
_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general