http://git-wip-us.apache.org/repos/asf/stratos/blob/c42d7c1d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/updater/ApplicationsUpdater.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/updater/ApplicationsUpdater.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/updater/ApplicationsUpdater.java index bbbfbf5..e987abf 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/updater/ApplicationsUpdater.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/applications/updater/ApplicationsUpdater.java @@ -23,8 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.messaging.domain.applications.locking.ApplicationLock; import org.apache.stratos.messaging.domain.applications.locking.ApplicationLockHierarchy; -import org.apache.stratos.messaging.domain.topology.locking.TopologyLock; -import org.apache.stratos.messaging.domain.topology.locking.TopologyLockHierarchy; +import org.apache.stratos.messaging.message.receiver.applications.ApplicationManager; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; /** @@ -67,21 +66,21 @@ public class ApplicationsUpdater { // Top level locks - should be used to lock the entire Topology /** - * Acquires write lock for the Complete Topology + * Acquires write lock for all Applications */ - public static void acquireWriteLock() { + public static void acquireWriteLockForApplications() { if(log.isDebugEnabled()) { - log.debug("Write lock acquired for Topology"); + log.debug("Write lock acquired for Applications"); } applicationLockHierarchy.getApplicationLock().acquireWriteLock(); } /** - * Releases write lock for the Complete Topology + * Releases write lock for all Applications */ - public static void releaseWriteLock() { + public static void releaseWriteLockForApplications() { if(log.isDebugEnabled()) { - log.debug("Write lock released for Topology"); + log.debug("Write lock released for Applications"); } applicationLockHierarchy.getApplicationLock().releaseWritelock(); } @@ -94,9 +93,9 @@ public class ApplicationsUpdater { public static void acquireWriteLockForApplication (String appId) { // acquire read lock for all Applications - TopologyManager.acquireReadLockForApplications(); + ApplicationManager.acquireReadLockForApplications(); - ApplicationLock applicationLock = applicationLockHierarchy.getLock(appId); + ApplicationLock applicationLock = applicationLockHierarchy.getLockForApplication(appId); if (applicationLock == null) { handleLockNotFound("Topology lock not found for Application " + appId); @@ -116,7 +115,7 @@ public class ApplicationsUpdater { */ public static void releaseWriteLockForApplication (String appId) { - ApplicationLock applicationLock = applicationLockHierarchy.getLock(appId); + ApplicationLock applicationLock = applicationLockHierarchy.getLockForApplication(appId); if (applicationLock == null) { handleLockNotFound("Topology lock not found for Application " + appId); @@ -129,7 +128,7 @@ public class ApplicationsUpdater { } // release read lock for all Applications - TopologyManager.releaseReadLockForApplications(); + ApplicationManager.releaseReadLockForApplications(); } private static void handleLockNotFound (String errorMsg) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/c42d7c1d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/CompleteTopologyMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/CompleteTopologyMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/CompleteTopologyMessageProcessor.java index 787ac74..ea1f83b 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/CompleteTopologyMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/CompleteTopologyMessageProcessor.java @@ -149,21 +149,6 @@ public class CompleteTopologyMessageProcessor extends MessageProcessor { } } - // add existing Applications to Topology - Collection<Application> applications = event.getTopology().getApplications(); - if (applications != null && !applications.isEmpty()) { - for (Application application : applications) { - topology.addApplication(application); - if (log.isDebugEnabled()) { - log.debug("Application with id [ " + application.getUniqueIdentifier() + " ] added to Topology"); - } - } - } else { - if (log.isDebugEnabled()) { - log.debug("No Application information found in Complete Topology event"); - } - } - if (log.isInfoEnabled()) { log.info("Topology initialized"); } http://git-wip-us.apache.org/repos/asf/stratos/blob/c42d7c1d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/updater/TopologyUpdater.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/updater/TopologyUpdater.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/updater/TopologyUpdater.java index 9867223..e4b1c66 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/updater/TopologyUpdater.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/updater/TopologyUpdater.java @@ -83,27 +83,7 @@ public class TopologyUpdater { topologyLockHierarchy.getCompleteTopologyLock().releaseWritelock(); } - // Application and Service write locks - /** - * Acquires write lock for the all Applications - */ - public static void acquireWriteLockForApplications() { - if(log.isDebugEnabled()) { - log.debug("Write lock acquired for Applications"); - } - topologyLockHierarchy.getApplicatioLock().acquireWriteLock(); - } - - /** - * Releases write lock for the all Applications - */ - public static void releaseWriteLockForApplications() { - if(log.isDebugEnabled()) { - log.debug("Write lock released for Applications"); - } - topologyLockHierarchy.getApplicatioLock().releaseWritelock(); - } - + // Service write locks /** * Acquires write lock for the all Services */ @@ -218,52 +198,6 @@ public class TopologyUpdater { TopologyManager.releaseReadLockForService(serviceName); } - /** - * Acquires write lock for the Application - * - * @param appId Application id - */ - public static void acquireWriteLockForApplication (String appId) { - - // acquire read lock for all Applications - TopologyManager.acquireReadLockForApplications(); - - TopologyLock topologyAppLock = topologyLockHierarchy.getTopologyLockForApplication(appId); - if (topologyAppLock == null) { - handleLockNotFound("Topology lock not found for Application " + appId); - - } else { - // now, lock Application - topologyAppLock.acquireWriteLock(); - if(log.isDebugEnabled()) { - log.debug("Write lock acquired for Application " + appId); - } - } - } - - /** - * Releases write lock for the Application - * - * @param appId Application id - */ - public static void releaseWriteLockForApplication (String appId) { - - TopologyLock topologyAppLock = topologyLockHierarchy.getTopologyLockForApplication(appId); - if (topologyAppLock == null) { - handleLockNotFound("Topology lock not found for Application " + appId); - - } else { - // release App lock - topologyAppLock.releaseWritelock(); - if(log.isDebugEnabled()) { - log.debug("Write lock released for Application " + appId); - } - } - - // release read lock for all Applications - TopologyManager.releaseReadLockForApplications(); - } - private static void handleLockNotFound (String errorMsg) { log.warn(errorMsg); //throw new RuntimeException(errorMsg); http://git-wip-us.apache.org/repos/asf/stratos/blob/c42d7c1d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/applications/ApplicationManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/applications/ApplicationManager.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/applications/ApplicationManager.java new file mode 100644 index 0000000..0c3aa0e --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/applications/ApplicationManager.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.messaging.message.receiver.applications; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.messaging.domain.applications.Applications; +import org.apache.stratos.messaging.domain.applications.locking.ApplicationLock; +import org.apache.stratos.messaging.domain.applications.locking.ApplicationLockHierarchy; + +public class ApplicationManager { + + private static final Log log = LogFactory.getLog(ApplicationManager.class); + + private static volatile Applications applications; + private static volatile ApplicationLockHierarchy applicationLockHierarchy = + ApplicationLockHierarchy.getInstance(); + + public static Applications getApplications () { + + if (applications == null) { + synchronized (ApplicationManager.class){ + if (applications == null) { + applications = new Applications(); + if(log.isDebugEnabled()) { + log.debug("Applications object created"); + } + } + } + } + return applications; + } + + /** + * Acquires read lock for all Applications + */ + public static void acquireReadLockForApplications() { + if(log.isDebugEnabled()) { + log.debug("Read lock acquired for Applications"); + } + applicationLockHierarchy.getApplicationLock().acquireReadLock(); + } + + /** + * Releases read lock for all Applications + */ + public static void releaseReadLockForApplications() { + if(log.isDebugEnabled()) { + log.debug("Read lock released for Applications"); + } + applicationLockHierarchy.getApplicationLock().releaseReadLock(); + } + + /** + * Acquires read lock for an Application + * + * @param applicationId Application Id to acquire read lock + */ + public static void acquireReadLockForApplication(String applicationId) { + + // acquire read lock for all Applications + acquireReadLockForApplications(); + + ApplicationLock applicationLock = applicationLockHierarchy.getLockForApplication(applicationId); + if (applicationLock == null) { + handleLockNotFound("Application lock not found for Application " + applicationId); + + } else { + applicationLock.acquireReadLock(); + if(log.isDebugEnabled()) { + log.debug("Read lock acquired for Application " + applicationId); + } + } + } + + /** + * Releases read lock for an Application + * + * @param applicationId Application Id to release read lock + */ + public static void releaseReadLockForApplication(String applicationId) { + + ApplicationLock applicationLock = applicationLockHierarchy.getLockForApplication(applicationId); + if (applicationLock == null) { + handleLockNotFound("Application lock not found for Application " + applicationId); + + } else { + applicationLock.releaseReadLock(); + if(log.isDebugEnabled()) { + log.debug("Read lock released for Application " + applicationId); + } + } + + // release read lock for all Applications + releaseReadLockForApplications(); + } + + private static void handleLockNotFound (String errorMsg) { + log.warn(errorMsg); + //throw new RuntimeException(errorMsg); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/c42d7c1d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java index 1d74616..159e128 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/topology/TopologyManager.java @@ -85,26 +85,7 @@ public class TopologyManager { topologyLockHierarchy.getCompleteTopologyLock().releaseReadLock(); } - // Application and Service read locks - /** - * Acquires read lock for the all Applications - */ - public static void acquireReadLockForApplications() { - if(log.isDebugEnabled()) { - log.debug("Read lock acquired for Applications"); - } - topologyLockHierarchy.getApplicatioLock().acquireReadLock(); - } - - /** - * Releases read lock for the all Applications - */ - public static void releaseReadLockForApplications() { - if(log.isDebugEnabled()) { - log.debug("Read lock released for Applications"); - } - topologyLockHierarchy.getApplicatioLock().releaseReadLock(); - } + // Service read locks /** * Acquires read lock for the all Services @@ -222,52 +203,6 @@ public class TopologyManager { releaseReadLockForService(serviceName); } - /** - * Acquires read lock for the Application - * - * @param appId Application id - */ - public static void acquireReadLockForApplication (String appId) { - - // acquire read lock for all Applications - acquireReadLockForApplications(); - - TopologyLock topologyAppLock = topologyLockHierarchy.getTopologyLockForApplication(appId); - if (topologyAppLock == null) { - handleLockNotFound("Topology lock not found for Application " + appId); - - } else { - // now, lock Application - topologyAppLock.acquireReadLock(); - if(log.isDebugEnabled()) { - log.debug("Read lock acquired for Application " + appId); - } - } - } - - /** - * Releases read lock for the Application - * - * @param appId Application id - */ - public static void releaseReadLockForApplication (String appId) { - - TopologyLock topologyAppLock = topologyLockHierarchy.getTopologyLockForApplication(appId); - if (topologyAppLock == null) { - handleLockNotFound("Topology lock not found for Application " + appId); - - } else { - // release App lock - topologyAppLock.releaseReadLock(); - if(log.isDebugEnabled()) { - log.debug("Read lock released for Application " + appId); - } - } - - // release read lock for all Applications - releaseReadLockForApplications(); - } - private static void handleLockNotFound (String errorMsg) { log.warn(errorMsg); //throw new RuntimeException(errorMsg);
