1 24 25 package org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking; 26 27 import java.util.ArrayList ; 28 29 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 30 31 37 public abstract class ErrorCheckingPolicy 38 { 39 40 public static final int RANDOM = 0; 41 42 43 public static final int ROUND_ROBIN = 1; 44 45 46 public static final int ALL = 2; 47 48 49 protected int nbOfNodes = 0; 50 51 protected int policy; 52 53 59 public ErrorCheckingPolicy(int policy, int numberOfNodes) 60 { 61 setPolicy(policy); 62 setNumberOfNodes(numberOfNodes); 63 } 64 65 71 public int getNumberOfNodes() 72 { 73 return nbOfNodes; 74 } 75 76 82 public void setNumberOfNodes(int numberOfNodes) 83 { 84 if (numberOfNodes < 3) 85 throw new IllegalArgumentException ( 86 "You must use at least 3 nodes for error checking (" + numberOfNodes 87 + " is not acceptable)"); 88 this.nbOfNodes = numberOfNodes; 89 } 90 91 97 public int getPolicy() 98 { 99 return policy; 100 } 101 102 108 public void setPolicy(int policy) 109 { 110 this.policy = policy; 111 } 112 113 121 public abstract ArrayList getBackends(ArrayList backends) 122 throws ErrorCheckingException; 123 124 129 public abstract String getInformation(); 130 131 136 public String getXml() 137 138 { 139 StringBuffer info = new StringBuffer (); 140 info.append("<" + DatabasesXmlTags.ELT_ErrorChecking + " />" 141 + DatabasesXmlTags.ATT_numberOfNodes + "=\"" + this.getNumberOfNodes() 142 + "\" " + DatabasesXmlTags.ATT_policy + "=\""); 143 switch (policy) 144 { 145 case RANDOM : 146 info.append(DatabasesXmlTags.VAL_random); 147 break; 148 case ROUND_ROBIN : 149 info.append(DatabasesXmlTags.VAL_roundRobin); 150 break; 151 case ALL : 152 info.append(DatabasesXmlTags.VAL_all); 153 break; 154 default : 155 break; 156 } 157 info.append("\"/>"); 158 return info.toString(); 159 } 160 } 161 | Popular Tags |