stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [22/32] stratos git commit: Used AtomicInteger to generate LB sequence.
Date Fri, 09 Oct 2015 14:35:35 GMT
Used AtomicInteger to generate LB sequence.


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

Branch: refs/heads/gsoc-projects-2015
Commit: 00441d4b4bfc5648cdbaa3090a73eff1aa733f86
Parents: d22721b
Author: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Authored: Sat Aug 1 17:01:39 2015 +0000
Committer: swapnilpatilRajaram <swapnil.patil@students.iiit.ac.in>
Committed: Sat Aug 1 17:01:39 2015 +0000

----------------------------------------------------------------------
 .../apache/stratos/aws/extension/AWSHelper.java | 31 +++++++++++---------
 1 file changed, 17 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/00441d4b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
----------------------------------------------------------------------
diff --git a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
index 50177bd..2251298 100644
--- a/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
+++ b/extensions/load-balancer/aws-extension/src/main/java/org/apache/stratos/aws/extension/AWSHelper.java
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -49,8 +50,8 @@ public class AWSHelper {
 	private String awsAccessKey;
 	private String awsSecretKey;
 	private String lbPrefix;
-	private int lbSequence;
-	private Object lbSequenceMutex;
+	private AtomicInteger lbSequence;
+
 	private String lbSecurityGroupName;
 	private String lbSecurityGroupDescription;
 
@@ -92,13 +93,13 @@ public class AWSHelper {
 
 			this.lbPrefix = properties.getProperty(Constants.LB_PREFIX);
 
-			if (this.lbPrefix.isEmpty() || this.lbPrefix.length() > Constants.LOAD_BALANCER_PREFIX_MAX_LENGTH)
{
+			if (this.lbPrefix.isEmpty()
+					|| this.lbPrefix.length() > Constants.LOAD_BALANCER_PREFIX_MAX_LENGTH) {
 				throw new LoadBalancerExtensionException(
 						"Invalid load balancer prefix.");
 			}
 
-			lbSequence = 0;
-			lbSequenceMutex = new Object();
+			lbSequence = new AtomicInteger(1);
 
 			this.lbSecurityGroupName = properties
 					.getProperty(Constants.LOAD_BALANCER_SECURITY_GROUP_NAME);
@@ -135,10 +136,7 @@ public class AWSHelper {
 	}
 
 	public int getNextLBSequence() {
-		synchronized (lbSequenceMutex) {
-			lbSequence++;
-			return lbSequence;
-		}
+		return lbSequence.getAndIncrement();
 	}
 
 	/**
@@ -173,7 +171,8 @@ public class AWSHelper {
 
 			createLoadBalancerRequest.setSecurityGroups(securityGroups);
 
-			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
+			lbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			CreateLoadBalancerResult clbResult = lbClient
 					.createLoadBalancer(createLoadBalancerRequest);
@@ -203,7 +202,8 @@ public class AWSHelper {
 		deleteLoadBalancerRequest.setLoadBalancerName(loadBalancerName);
 
 		try {
-			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
+			lbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			lbClient.deleteLoadBalancer(deleteLoadBalancerRequest);
 			return;
@@ -233,7 +233,8 @@ public class AWSHelper {
 				loadBalancerName, instances);
 
 		try {
-			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
+			lbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			RegisterInstancesWithLoadBalancerResult result = lbClient
 					.registerInstancesWithLoadBalancer(registerInstancesWithLoadBalancerRequest);
@@ -264,7 +265,8 @@ public class AWSHelper {
 				loadBalancerName, instances);
 
 		try {
-			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
+			lbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			DeregisterInstancesFromLoadBalancerResult result = lbClient
 					.deregisterInstancesFromLoadBalancer(deregisterInstancesFromLoadBalancerRequest);
@@ -295,7 +297,8 @@ public class AWSHelper {
 				loadBalancers);
 
 		try {
-			lbClient.setEndpoint(String.format(Constants.ELB_ENDPOINT_URL_FORMAT, region));
+			lbClient.setEndpoint(String.format(
+					Constants.ELB_ENDPOINT_URL_FORMAT, region));
 
 			DescribeLoadBalancersResult result = lbClient
 					.describeLoadBalancers(describeLoadBalancersRequest);


Mime
View raw message