OpenAM ServiceListener question

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

OpenAM ServiceListener question

Mark Boyd ソフトウェア 建築家
We have a number of openAM admin console services that we have added to openAM that show up in the console at paths like Configuration/Global/XyzService. And we have singleton factories like the following for acquiring that values from those services. 

Here is my problem. Regularly, servers will stop showing that last logger.info line in the logs and behave as if the config change listener is no longer getting updates. i.e.: the server is behaving as if the old values are still stored in the XyzConfig instance. I just tested today and 4 of 8 servers were not seeing updates and needed to be restarted.

As you can see we are registering a single listener instance and never doing so again. Are we using such listeners incorrectly?

Thanks.

Mark


Example Code:

public class XyzConfig {

   private static XyzConfig instance;

   ... other variables

    public static final XyzConfig getInstance() {
        if (instance == null) {
            try {
                instance = new XyzConfig();
            }
            catch(Throwable t) {
                logger.error("Unable to load XyzConfig.", t);
                // just return a null value in this case and handle appropriately.
            }
        }
        return instance;
    }

    private XyzConfig() {
        SSOToken admTk = (SSOToken) AccessController.doPrivileged(
                AdminTokenAction.getInstance());
        ServiceConfigManager mgr = null;
        try {
            mgr = new ServiceConfigManager(CFG_SERVICE_NAME, admTk);
        } catch (SMSException | SSOException e) {
            logger.error("Unable to load OpenAM ServiceConfigManager to obtain " + CFG_SERVICE_NAME +" config.", e);
        }

        if (mgr != null) {
            if (XyzConfig.instance == null) {
                mgr.addListener(new ConfigChangeListener());
            }
            ServiceConfig serviceConf = null;
            try {
                serviceConf = mgr.getGlobalConfig("default");
            } catch (SMSException | SSOException e) {
                logger.error("Unable to load default Global Config to obtain " + CFG_SERVICE_NAME +".", e);
            }

            if (serviceConf != null) {
                Map<String, Set<String>> map = serviceConf.getAttributes();
                ... load values into instance variables
            }
        }
        // log what was loaded if message level debugging is activated.
        logger.info("Loaded: {}", new Object[] {this.toString()});
    }

    ... getter methods for loaded values and toString for showing current values in log

    private static class ConfigChangeListener implements ServiceListener {

        private ConfigChangeListener() {
            logger.info("Change Listener instantiated.");
        }

        @Override
        public void schemaChanged(String serviceName, String version) {
            // ignore
        }

        @Override
        public void organizationConfigChanged(String serviceName, String version, String orgName, String groupName,
           String serviceComponent, int type) {
            // ignore since we don't have any explicit realm related data in our config
        }

        @Override
        public void globalConfigChanged(String serviceName, String version, String groupName, String serviceComponent, int type) {
            logger.info("Config changed. Loading...");
            XyzConfig.instance = new XyzConfig();
        }
    }
}





_______________________________________________
Visit the OpenAM forum at https://forgerock.org/forum/fr-projects/openam/
OpenAM mailing list
[hidden email]
https://lists.forgerock.org/mailman/listinfo/openam