Updated Branches: refs/heads/master a1b99ddbc -> b695c540a
making RegistryManager Singleton, efficiently Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/b695c540 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/b695c540 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/b695c540 Branch: refs/heads/master Commit: b695c540abb8c98302e648e8537b61373635b4da Parents: 902f06c Author: Nirmal Fernando <[email protected]> Authored: Mon Dec 16 10:16:57 2013 +0530 Committer: Nirmal Fernando <[email protected]> Committed: Mon Dec 16 10:17:23 2013 +0530 ---------------------------------------------------------------------- .../controller/registry/RegistryManager.java | 24 +++++++++----------- 1 file changed, 11 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/b695c540/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java index 0309c0d..58862e4 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java @@ -40,26 +40,24 @@ import org.wso2.carbon.registry.core.exceptions.ResourceNotFoundException; public class RegistryManager { private final static Log log = LogFactory.getLog(RegistryManager.class); private static Registry registryService; - private static RegistryManager registryManager; - public static RegistryManager getInstance() { + private static class Holder { + static final RegistryManager INSTANCE = new RegistryManager(); + } + public static RegistryManager getInstance() { registryService = ServiceReferenceHolder.getInstance().getRegistry(); - - synchronized (RegistryManager.class) { - if (registryManager == null) { - if (registryService == null) { - // log.warn("Registry Service is null. Hence unable to fetch data from registry."); - return registryManager; - } - registryManager = new RegistryManager(); - } + if (registryService == null) { + log.warn("Registry Service is null. Hence unable to fetch data from registry."); + return null; } - return registryManager; - } + return Holder.INSTANCE; + } + private RegistryManager() { try { + if (!registryService.resourceExists(CloudControllerConstants.CLOUD_CONTROLLER_RESOURCE)) { registryService.put(CloudControllerConstants.CLOUD_CONTROLLER_RESOURCE, registryService.newCollection());
