1 23 24 package org.continuent.sequoia.controller.loadbalancer.policies.createtable; 25 26 import java.util.ArrayList ; 27 28 import org.continuent.sequoia.common.xml.DatabasesXmlTags; 29 import org.continuent.sequoia.controller.backend.DatabaseBackend; 30 31 39 public abstract class CreateTableRule 40 { 41 42 protected ArrayList backendList; 43 44 45 protected int nbOfNodes = 0; 46 47 51 protected String tableName = null; 52 53 protected int policy; 54 55 60 public CreateTableRule(int policy) 61 { 62 this.policy = policy; 63 backendList = new ArrayList (); 64 } 65 66 72 public CreateTableRule(int policy, ArrayList backendList) 73 { 74 if (backendList == null) 75 throw new IllegalArgumentException ( 76 "Null backendList in CreateTableRule constructor"); 77 78 this.policy = policy; 79 this.backendList = backendList; 80 } 81 82 87 public void addBackendName(String name) 88 { 89 backendList.add(name); 90 } 91 92 97 public ArrayList getBackendList() 98 { 99 return backendList; 100 } 101 102 107 public int getNumberOfNodes() 108 { 109 return nbOfNodes; 110 } 111 112 117 public void setNumberOfNodes(int numberOfNodes) 118 { 119 this.nbOfNodes = numberOfNodes; 120 } 121 122 127 public String getTableName() 128 { 129 return tableName; 130 } 131 132 137 public void setTableName(String tableName) 138 { 139 this.tableName = tableName; 140 } 141 142 147 public int getPolicy() 148 { 149 return policy; 150 } 151 152 157 public void setPolicy(int policy) 158 { 159 this.policy = policy; 160 } 161 162 167 public boolean isDefaultRule() 168 { 169 return this.tableName == null; 170 } 171 172 181 public ArrayList getBackends(ArrayList backends) throws CreateTableException 182 { 183 ArrayList clonedList; 184 185 int size = backends.size(); 186 187 if (backendList.size() > 0) 188 { clonedList = new ArrayList (size); 190 for (int i = 0; i < size; i++) 191 { 192 DatabaseBackend db = (DatabaseBackend) backends.get(i); 193 if (db.isWriteEnabled() && backendList.contains(db.getName())) 194 clonedList.add(db); 195 } 196 } 197 else 198 { clonedList = new ArrayList (size); 200 for (int i = 0; i < size; i++) 201 { 202 DatabaseBackend db = (DatabaseBackend) backends.get(i); 203 if (db.isWriteEnabled()) 204 clonedList.add(db); 205 } 206 } 207 208 return clonedList; 209 } 210 211 216 public abstract String getInformation(); 217 218 223 public String getXml() 224 225 { 226 StringBuffer info = new StringBuffer (); 227 info.append("<" + DatabasesXmlTags.ELT_CreateTable + " " 228 + DatabasesXmlTags.ATT_tableName + "=\"" + tableName + "\" " 229 + DatabasesXmlTags.ATT_policy + "=\"" 230 + CreateTablePolicy.getXmlValue(policy) + "\" " 231 + DatabasesXmlTags.ATT_numberOfNodes + "=\"" + nbOfNodes + "\">"); 232 ArrayList list = this.getBackendList(); 233 int count = list.size(); 234 for (int i = 0; i < count; i++) 235 { 236 info 237 .append("<" + DatabasesXmlTags.ELT_BackendName + " " 238 + DatabasesXmlTags.ATT_name + "=\"" + ((String ) list.get(i)) 239 + "\"/>"); 240 } 241 info.append("</" + DatabasesXmlTags.ELT_CreateTable + ">"); 242 return info.toString(); 243 } 244 245 } 246 | Popular Tags |