stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject stratos git commit: Updating load balancer to use distributed object provider osgi service
Date Tue, 02 Dec 2014 02:14:54 GMT
Repository: stratos
Updated Branches:
  refs/heads/master 248e4d6b1 -> 7978da463


Updating load balancer to use distributed object provider osgi service


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/7978da46
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/7978da46
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/7978da46

Branch: refs/heads/master
Commit: 7978da4637d0a508eb7762874d717365c2a882f8
Parents: 248e4d6
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Tue Dec 2 07:44:30 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Tue Dec 2 07:44:50 2014 +0530

----------------------------------------------------------------------
 .../context/map/AlgorithmContextMap.java        | 97 ++------------------
 .../internal/LoadBalancerServiceComponent.java  | 25 ++---
 .../internal/ServiceReferenceHolder.java        | 22 ++---
 3 files changed, 21 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/7978da46/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/AlgorithmContextMap.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/AlgorithmContextMap.java
b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/AlgorithmContextMap.java
index 49ecf2f..2c03ccb 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/AlgorithmContextMap.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/AlgorithmContextMap.java
@@ -19,18 +19,12 @@
 
 package org.apache.stratos.load.balancer.context.map;
 
-import com.hazelcast.core.HazelcastInstance;
-import com.hazelcast.core.ILock;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.load.balancer.context.LoadBalancerContext;
+import org.apache.stratos.common.clustering.DistributedObjectProvider;
 import org.apache.stratos.load.balancer.internal.ServiceReferenceHolder;
-import org.wso2.carbon.caching.impl.DistributedMapProvider;
-import org.wso2.carbon.caching.impl.MapEntryListener;
 
-import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Algorithm context map is a singleton class for managing load balancing algorithm context
@@ -43,46 +37,13 @@ public class AlgorithmContextMap {
     private static AlgorithmContextMap instance;
 
     private final Map<String, Integer> clusterMemberIndexMap;
+    private final DistributedObjectProvider distributedObjectProvider;
 
     private AlgorithmContextMap() {
-        if (LoadBalancerContext.getInstance().isClustered()) {
-            DistributedMapProvider distributedMapProvider = ServiceReferenceHolder.getInstance().getDistributedMapProvider();
-            clusterMemberIndexMap = distributedMapProvider.getMap(LOAD_BALANCER_ALGORITHM_CONTEXT_MAP,
-                    new MapEntryListener() {
-                        @Override
-                        public <X> void entryAdded(X x) {
-                            if(log.isDebugEnabled()) {
-                                log.debug("Entry added to distributed algorithm context map:
" + x);
-                            }
-                        }
-
-                        @Override
-                        public <X> void entryRemoved(X x) {
-                            if(log.isDebugEnabled()) {
-                                log.debug("Entry removed from distributed algorithm context
map: " + x);
-                            }
-                        }
-
-                        @Override
-                        public <X> void entryUpdated(X x) {
-                            if(log.isDebugEnabled()) {
-                                log.debug("Entry updated in distributed algorithm context
map: " + x);
-                            }
-                        }
-                    });
-            if (clusterMemberIndexMap != null) {
-                if (log.isInfoEnabled()) {
-                    log.info("Load balancer context map initialized in distributed mode");
-                }
-            } else {
-                log.error("Could not initialize algorithm context map from distributed map
provider");
-            }
-        } else {
-            clusterMemberIndexMap = new ConcurrentHashMap<String, Integer>();
-            if (log.isInfoEnabled()) {
-                log.info("Load balancer context map initialized locally");
-            }
-        }
+        // Initialize distributed object provider
+        distributedObjectProvider = ServiceReferenceHolder.getInstance().getDistributedObjectProvider();
+        // Initialize cluster->memberIndex map
+        clusterMemberIndexMap = distributedObjectProvider.getMap(LOAD_BALANCER_ALGORITHM_CONTEXT_MAP);
     }
 
     public static AlgorithmContextMap getInstance() {
@@ -100,56 +61,14 @@ public class AlgorithmContextMap {
         return String.format("%s-%s", serviceName, clusterId);
     }
 
-    private com.hazelcast.core.ILock acquireDistributedLock(Object object) {
-        if (log.isDebugEnabled()) {
-            log.debug("Acquiring distributed lock for algorithm context map...");
-        }
-        HazelcastInstance hazelcastInstance = ServiceReferenceHolder.getInstance().getHazelcastInstance();
-        ILock lock = hazelcastInstance.getLock(object);
-        if (log.isDebugEnabled()) {
-            log.debug("Distributed lock acquired for algorithm context map");
-        }
-        return lock;
-    }
-
-    private void releaseDistributedLock(ILock lock) {
-        if (log.isDebugEnabled()) {
-            log.debug("Releasing distributed lock for algorithm context map...");
-        }
-        lock.forceUnlock();
-        if (log.isDebugEnabled()) {
-            log.debug("Distributed lock released for algorithm context map");
-        }
-    }
-
     public void putCurrentMemberIndex(String serviceName, String clusterId, int currentMemberIndex)
{
         String key = constructKey(serviceName, clusterId);
-        if (LoadBalancerContext.getInstance().isClustered()) {
-            ILock lock = null;
-            try {
-                lock = acquireDistributedLock(clusterMemberIndexMap);
-                clusterMemberIndexMap.put(key, currentMemberIndex);
-            } finally {
-                releaseDistributedLock(lock);
-            }
-        } else {
-            clusterMemberIndexMap.put(key, currentMemberIndex);
-        }
+        distributedObjectProvider.putToMap(clusterMemberIndexMap, key, currentMemberIndex);
     }
 
     public void removeCluster(String serviceName, String clusterId) {
         String key = constructKey(serviceName, clusterId);
-        if (LoadBalancerContext.getInstance().isClustered()) {
-            ILock lock = null;
-            try {
-                lock = acquireDistributedLock(clusterMemberIndexMap);
-                clusterMemberIndexMap.remove(key);
-            } finally {
-                releaseDistributedLock(lock);
-            }
-        } else {
-            clusterMemberIndexMap.remove(key);
-        }
+        distributedObjectProvider.removeFromMap(clusterMemberIndexMap, key);
     }
 
     public int getCurrentMemberIndex(String serviceName, String clusterId) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/7978da46/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
index 579512e..aa5e2ef 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
@@ -19,12 +19,12 @@
 
 package org.apache.stratos.load.balancer.internal;
 
-import com.hazelcast.core.HazelcastInstance;
 import org.apache.axis2.clustering.ClusteringAgent;
 import org.apache.axis2.deployment.DeploymentEngine;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.clustering.DistributedObjectProvider;
 import org.apache.stratos.load.balancer.endpoint.EndpointDeployer;
 import org.apache.stratos.load.balancer.messaging.LoadBalancerTenantEventReceiver;
 import org.apache.stratos.load.balancer.messaging.LoadBalancerTopologyEventReceiver;
@@ -45,7 +45,6 @@ import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.deployers.SynapseArtifactDeploymentStore;
 import org.apache.synapse.endpoints.Endpoint;
 import org.osgi.service.component.ComponentContext;
-import org.wso2.carbon.caching.impl.DistributedMapProvider;
 import org.wso2.carbon.mediation.dependency.mgt.services.DependencyManagementService;
 import org.wso2.carbon.mediation.initializer.ServiceBusConstants;
 import org.wso2.carbon.mediation.initializer.ServiceBusUtils;
@@ -64,10 +63,8 @@ import java.util.Set;
 
 /**
  * @scr.component name="org.apache.stratos.load.balancer.internal.LoadBalancerServiceComponent"
immediate="true"
- * @scr.reference name="hazelcast.instance.service" interface="com.hazelcast.core.HazelcastInstance"
- *                cardinality="0..1"policy="dynamic" bind="setHazelcastInstance" unbind="unsetHazelcastInstance"
- * @scr.reference name="distributedMapProvider" interface="org.wso2.carbon.caching.impl.DistributedMapProvider"
- *                cardinality="0..1" policy="dynamic" bind="setDistributedMapProvider" unbind="unsetDistributedMapProvider"
+ * @scr.reference name="distributedObjectProvider" interface="org.apache.stratos.common.clustering.DistributedObjectProvider"
+ *                cardinality="1..1" policy="dynamic" bind="setDistributedObjectProvider"
unbind="unsetDistributedObjectProvider"
  * @scr.reference name="configuration.context.service" interface="org.wso2.carbon.utils.ConfigurationContextService"
  *                cardinality="1..1" policy="dynamic" bind="setConfigurationContextService"
unbind="unsetConfigurationContextService"
  * @scr.reference name="synapse.config.service" interface="org.wso2.carbon.mediation.initializer.services.SynapseConfigurationService"
@@ -417,19 +414,11 @@ public class LoadBalancerServiceComponent {
         ServiceReferenceHolder.getInstance().setRealmService(null);
     }
 
-    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
-        ServiceReferenceHolder.getInstance().setHazelcastInstance(hazelcastInstance);
+    protected void setDistributedObjectProvider(DistributedObjectProvider distributedObjectProvider)
{
+        ServiceReferenceHolder.getInstance().setDistributedObjectProvider(distributedObjectProvider);
     }
 
-    public void unsetHazelcastInstance(HazelcastInstance hazelcastInstance) {
-        ServiceReferenceHolder.getInstance().setHazelcastInstance(null);
-    }
-
-    protected void setDistributedMapProvider(DistributedMapProvider mapProvider) {
-        ServiceReferenceHolder.getInstance().setDistributedMapProvider(mapProvider);
-    }
-
-    protected void unsetDistributedMapProvider(DistributedMapProvider mapProvider) {
-        ServiceReferenceHolder.getInstance().setDistributedMapProvider(null);
+    protected void unsetDistributedObjectProvider(DistributedObjectProvider distributedObjectProvider)
{
+        ServiceReferenceHolder.getInstance().setDistributedObjectProvider(null);
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/7978da46/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
index 719eb10..54e9f25 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
@@ -19,14 +19,13 @@
 
 package org.apache.stratos.load.balancer.internal;
 
-import com.hazelcast.core.HazelcastInstance;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.clustering.DistributedObjectProvider;
 import org.apache.stratos.load.balancer.exception.TenantAwareLoadBalanceEndpointException;
 import org.apache.synapse.config.SynapseConfiguration;
-import org.wso2.carbon.caching.impl.DistributedMapProvider;
 import org.wso2.carbon.mediation.dependency.mgt.services.DependencyManagementService;
 import org.wso2.carbon.registry.core.session.UserRegistry;
 import org.wso2.carbon.user.core.service.RealmService;
@@ -45,9 +44,8 @@ public class ServiceReferenceHolder {
     private UserRegistry configRegistry;
     private UserRegistry governanceRegistry;
     private DependencyManagementService dependencyManager;
-    private DistributedMapProvider distributedMapProvider;
-    private HazelcastInstance hazelcastInstance;
     private RealmService realmService;
+    private DistributedObjectProvider distributedObjectProvider;
 
     private ServiceReferenceHolder() {
     }
@@ -130,19 +128,11 @@ public class ServiceReferenceHolder {
         this.configCtxt = configCtxt;
     }
 
-    public void setDistributedMapProvider(DistributedMapProvider distributedMapProvider)
{
-        this.distributedMapProvider = distributedMapProvider;
+    public void setDistributedObjectProvider(DistributedObjectProvider distributedObjectProvider)
{
+        this.distributedObjectProvider = distributedObjectProvider;
     }
 
-    public DistributedMapProvider getDistributedMapProvider() {
-        return distributedMapProvider;
-    }
-
-    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
-        this.hazelcastInstance = hazelcastInstance;
-    }
-
-    public HazelcastInstance getHazelcastInstance() {
-        return hazelcastInstance;
+    public DistributedObjectProvider getDistributedObjectProvider() {
+        return distributedObjectProvider;
     }
 }


Mime
View raw message