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