1 23 24 package org.continuent.sequoia.controller.loadbalancer.policies.createtable; 25 26 import java.util.ArrayList ; 27 28 37 public class CreateTableRoundRobin extends CreateTableRule 38 { 39 private int index = 0; 40 41 44 public CreateTableRoundRobin() 45 { 46 super(CreateTablePolicy.ROUND_ROBIN); 47 } 48 49 54 public CreateTableRoundRobin(ArrayList backendList) 55 { 56 super(CreateTablePolicy.ROUND_ROBIN, backendList); 57 } 58 59 62 public ArrayList getBackends(ArrayList backends) throws CreateTableException 63 { 64 if (nbOfNodes == 0) 65 return null; 66 67 ArrayList clonedList = super.getBackends(backends); 68 69 int clonedSize = clonedList.size(); 70 71 if (nbOfNodes == clonedSize) 72 return clonedList; 73 else if (nbOfNodes > clonedSize) 74 throw new CreateTableException( 75 "Asking for more backends (" 76 + nbOfNodes 77 + ") than available (" 78 + clonedSize 79 + ")"); 80 81 ArrayList result = new ArrayList (nbOfNodes); 82 83 synchronized (this) 84 { for (int i = 0; i < nbOfNodes; i++) 86 { 87 index = (index + 1) % clonedSize; 88 if (index - i < 0) 89 result.add(clonedList.remove(0)); 90 else 91 result.add(clonedList.remove(index - i)); 92 } 93 } 94 95 return result; 96 } 97 98 101 public String getInformation() 102 { 103 String s; 104 if (tableName == null) 105 s = "Default rule create table on "; 106 else 107 s = "Rule for table " + tableName + " create table on "; 108 109 return s + nbOfNodes + " node(s) in round-robin from " + backendList; 110 } 111 } 112 | Popular Tags |