Updated Branches:
  refs/heads/master f6c45151f -> 3a5f074af

Fixing iterator exception while removing active member


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

Branch: refs/heads/master
Commit: 86ec1ff01e03b64c7f5dd6c5f51c2f3a5ca9630d
Parents: efbc7af
Author: Lahiru Sandaruwan <[email protected]>
Authored: Thu Jan 16 09:31:36 2014 +0530
Committer: Lahiru Sandaruwan <[email protected]>
Committed: Thu Jan 16 09:31:36 2014 +0530

----------------------------------------------------------------------
 .../stratos/autoscaler/PartitionContext.java    | 25 ++++++++++----------
 .../autoscaler/algorithm/OneAfterAnother.java   |  6 ++---
 2 files changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/86ec1ff0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/PartitionContext.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/PartitionContext.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/PartitionContext.java
index 5e0024d..24119ce 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/PartitionContext.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/PartitionContext.java
@@ -157,9 +157,9 @@ public class PartitionContext implements Serializable{
         if (memberId == null) {
             return;
         }
-        for (Iterator<MemberContext> iterator = pendingMembers.listIterator(); 
-                iterator.hasNext();) {
-            MemberContext pendingMember = (MemberContext) iterator.next();
+        Iterator<MemberContext> iterator = pendingMembers.listIterator();
+        while (iterator.hasNext()) {
+            MemberContext pendingMember = iterator.next();
             if(pendingMember == null) {
                 iterator.remove();
                 continue;
@@ -184,9 +184,9 @@ public class PartitionContext implements Serializable{
         if (memberId == null) {
             return;
         }
-        for (Iterator<MemberContext> iterator = activeMembers.listIterator();
-                iterator.hasNext();) {
-            MemberContext activeMember = (MemberContext) iterator.next();
+        Iterator<MemberContext> iterator = activeMembers.listIterator();
+        while ( iterator.hasNext()) {
+            MemberContext activeMember = iterator.next();
             if(activeMember == null) {
                 iterator.remove();
                 continue;
@@ -332,10 +332,11 @@ public class PartitionContext implements Serializable{
     public void removeActiveMemberById(String memberId) {
 
         synchronized (activeMembers) {
+            Iterator<MemberContext> iterator = activeMembers.listIterator();
+            while (iterator.hasNext()) {
+                MemberContext memberContext = iterator.next();
 
-            for (Iterator<MemberContext> iterator = 
activeMembers.listIterator(); iterator.hasNext();) {
-                String currentMemberId = ((MemberContext) 
iterator).getMemberId();
-                if(memberId.equals(currentMemberId)){
+                if(memberId.equals(memberContext.getMemberId())){
 
                     iterator.remove();
                     break;
@@ -360,9 +361,9 @@ public class PartitionContext implements Serializable{
                 List<MemberContext> pendingMembers = ctxt.getPendingMembers();
                 
                 synchronized (pendingMembers) {
-
-                    for (Iterator<MemberContext> iterator = 
pendingMembers.listIterator(); iterator.hasNext();) {
-                        MemberContext pendingMember = (MemberContext) 
iterator.next();
+                    Iterator<MemberContext> iterator = 
pendingMembers.listIterator();
+                    while ( iterator.hasNext()) {
+                        MemberContext pendingMember = iterator.next();
 
                         if (pendingMember == null) {
                             continue;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/86ec1ff0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
index 65cbdfc..becfd5b 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
@@ -106,15 +106,15 @@ public class OneAfterAnother implements 
AutoscaleAlgorithm {
                         // current partition is free
                         if (log.isDebugEnabled())
                             log.debug(String.format("A free space found for 
scale down in partition %s [current] %s [min] %s",
-                                    currentPartitionId, 
networkPartitionContext.getNonTerminatedMemberCountOfPartition(currentPartitionId),
+                                    currentPartitionId, 
networkPartitionContext.getActiveMemberCount(currentPartitionId),
                                                                     
currentPartition.getPartitionMin()))  ;
                         return currentPartition;
                     } else {
                         if (currentPartitionIndex == 0) {
                             if (log.isDebugEnabled())
                                 log.debug(String.format("Partition %s reached 
with no space to scale down," +
-                                        "[current] %s [mib] %s", 
currentPartitionId,
-                                        
networkPartitionContext.getNonTerminatedMemberCountOfPartition(currentPartitionId),
+                                        "[current] %s [min] %s", 
currentPartitionId,
+                                        
networkPartitionContext.getActiveMemberCount(currentPartitionId),
                                         currentPartition.getPartitionMin()));
                             return null;
                         }

Reply via email to