You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2015/06/24 09:36:31 UTC
stratos git commit: Fixing issue of generating lock more than one due
to syncronization issue
Repository: stratos
Updated Branches:
refs/heads/master a09a41f69 -> ba6f30ea9
Fixing issue of generating lock more than one due to syncronization issue
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/ba6f30ea
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/ba6f30ea
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/ba6f30ea
Branch: refs/heads/master
Commit: ba6f30ea944b2a38cf025523dafc4d9a11e65977
Parents: a09a41f
Author: reka <rt...@gmail.com>
Authored: Wed Jun 24 12:39:46 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Wed Jun 24 13:06:19 2015 +0530
----------------------------------------------------------------------
.../locking/ApplicationLockHierarchy.java | 18 ++++++++++-------
.../topology/locking/TopologyLockHierarchy.java | 21 +++++++-------------
2 files changed, 18 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/ba6f30ea/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/locking/ApplicationLockHierarchy.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/locking/ApplicationLockHierarchy.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/locking/ApplicationLockHierarchy.java
index f341de2..e45d87f 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/locking/ApplicationLockHierarchy.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/locking/ApplicationLockHierarchy.java
@@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
public class ApplicationLockHierarchy {
@@ -39,7 +40,7 @@ public class ApplicationLockHierarchy {
private ApplicationLockHierarchy() {
this.applicationLock = new ApplicationLock();
- this.appIdToApplicationLockMap = new HashMap<String, ApplicationLock>();
+ this.appIdToApplicationLockMap = new ConcurrentHashMap<String, ApplicationLock>();
}
public static ApplicationLockHierarchy getInstance() {
@@ -55,16 +56,19 @@ public class ApplicationLockHierarchy {
return applicationLockHierarchy;
}
- public ApplicationLock getLockForApplication(String appId) {
+ public synchronized ApplicationLock getLockForApplication(String appId) {
ApplicationLock applicationLock = appIdToApplicationLockMap.get(appId);
+
if (applicationLock == null) {
- synchronized (ApplicationLockHierarchy.class) {
- if (applicationLock == null) {
- applicationLock = new ApplicationLock();
- appIdToApplicationLockMap.put(appId, applicationLock);
- }
+ applicationLock = new ApplicationLock();
+ if (log.isInfoEnabled()) {
+ log.info("Lock created for application: [application-id] " + appId +
+ " " + applicationLock.toString() + " size of application lock in map : " + appIdToApplicationLockMap.size());
}
+ appIdToApplicationLockMap.put(appId, applicationLock);
}
+
+
return applicationLock;
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/ba6f30ea/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/locking/TopologyLockHierarchy.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/locking/TopologyLockHierarchy.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/locking/TopologyLockHierarchy.java
index b139ea1..8911ebc 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/locking/TopologyLockHierarchy.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/locking/TopologyLockHierarchy.java
@@ -61,28 +61,21 @@ public class TopologyLockHierarchy {
return topologyLockHierarchy;
}
- public TopologyLock getTopologyLockForService(String serviceName, boolean forceCreationIfNotFound) {
+ public synchronized TopologyLock getTopologyLockForService(String serviceName, boolean forceCreationIfNotFound) {
TopologyLock topologyLock = serviceNameToTopologyLockMap.get(serviceName);
if (topologyLock == null && forceCreationIfNotFound) {
- synchronized (TopologyLockHierarchy.class) {
- if (topologyLock == null) {
- topologyLock = new TopologyLock();
- serviceNameToTopologyLockMap.put(serviceName, topologyLock);
- }
- }
+ topologyLock = new TopologyLock();
+ serviceNameToTopologyLockMap.put(serviceName, topologyLock);
+
}
return topologyLock;
}
- public TopologyLock getTopologyLockForCluster(String clusterId, boolean forceCreationIfNotFound) {
+ public synchronized TopologyLock getTopologyLockForCluster(String clusterId, boolean forceCreationIfNotFound) {
TopologyLock topologyLock = clusterIdToTopologyLockMap.get(clusterId);
if (topologyLock == null && forceCreationIfNotFound) {
- synchronized (TopologyLockHierarchy.class) {
- if (topologyLock == null) {
- topologyLock = new TopologyLock();
- clusterIdToTopologyLockMap.put(clusterId, topologyLock);
- }
- }
+ topologyLock = new TopologyLock();
+ clusterIdToTopologyLockMap.put(clusterId, topologyLock);
}
return topologyLock;
}