You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Mark Derricutt <ma...@talios.com> on 2008/10/30 03:37:43 UTC

SCR and ConfigAdmin

Hi all,

I'm having an odd problem with ConfigAdmin and my SCR based services.  When
I first start my bundle, I see my service get activated() without
configuration data, the its deactivated and reactivated with configuration
data in its ComponentContext.getProperties() - this is all as expected and
fine.

However, if I stop and restart my bundle, I only see the initial service
activation() without any configuration information.

Via the OSGi webconsole I can see that I still configuration information,
and its listed as being bound to the package - should I be doing something
else to lookup the configuration?  I've noticed the same behaviour when I
uninstall my bundle, and then reinstall it - the service comes back up, but
no configuration.

The service is fairly simple, and just bootstraps another service:

public class DataProviderAdminImpl {

    private ServiceRegistration databaseProviderReference;
    private DatabaseProviderImpl databaseProvider;

    protected synchronized void activate(ComponentContext componentContext)
{
        Dictionary dictionary = componentContext.getProperties();

        String host = (String) dictionary.get("smx3.database.host");
        Integer port = (Integer) dictionary.get("smx3.database.port");
        String databaseName = (String) dictionary.get("smx3.database.name");
        String userName = (String) dictionary.get("smx3.database.username");
        String password = (String) dictionary.get("smx3.database.password");

        if (isNotNullOrEmpty(host, databaseName, userName, password, port))
{
            databaseProvider = new DatabaseProviderImpl(host, port,
databaseName, userName, password);
            databaseProviderReference =
componentContext.getBundleContext().registerService(
                DatabaseProvider.class.getName(),
                databaseProvider,
                null);
        }
    }

    protected synchronized void deactivate(ComponentContext
componentContext) throws NamingException {
        if (databaseProviderReference != null) {
            databaseProviderReference.unregister();
            databaseProviderReference = null;
            databaseProvider = null;
        }
    }

}


-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan