00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking;
00026
00027 import java.util.ArrayList;
00028
00029 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00030
00031
00032
00033
00034
00035
00036
00037 public abstract class ErrorCheckingPolicy
00038 {
00039
00040 public static final int RANDOM = 0;
00041
00042
00043 public static final int ROUND_ROBIN = 1;
00044
00045
00046 public static final int ALL = 2;
00047
00048
00049 protected int nbOfNodes = 0;
00050
00051 protected int policy;
00052
00053
00054
00055
00056
00057
00058
00059 public ErrorCheckingPolicy(int policy, int numberOfNodes)
00060 {
00061 setPolicy(policy);
00062 setNumberOfNodes(numberOfNodes);
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 public int getNumberOfNodes()
00072 {
00073 return nbOfNodes;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082 public void setNumberOfNodes(int numberOfNodes)
00083 {
00084 if (numberOfNodes < 3)
00085 throw new IllegalArgumentException(
00086 "You must use at least 3 nodes for error checking ("
00087 + numberOfNodes
00088 + " is not acceptable)");
00089 this.nbOfNodes = numberOfNodes;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098 public int getPolicy()
00099 {
00100 return policy;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109 public void setPolicy(int policy)
00110 {
00111 this.policy = policy;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 public abstract ArrayList getBackends(ArrayList backends)
00123 throws ErrorCheckingException;
00124
00125
00126
00127
00128
00129
00130 public abstract String getInformation();
00131
00132
00133
00134
00135
00136
00137 public String getXml()
00138
00139 {
00140 StringBuffer info = new StringBuffer();
00141 info.append(
00142 "<"
00143 + DatabasesXmlTags.ELT_ErrorChecking
00144 + " />"
00145 + DatabasesXmlTags.ATT_numberOfNodes
00146 + "=\""
00147 + this.getNumberOfNodes()
00148 + "\" "
00149 + DatabasesXmlTags.ATT_policy
00150 + "=\"");
00151 switch (policy)
00152 {
00153 case RANDOM :
00154 info.append(DatabasesXmlTags.VAL_random);
00155 case ROUND_ROBIN :
00156 info.append(DatabasesXmlTags.VAL_roundRobin);
00157 case ALL :
00158 info.append(DatabasesXmlTags.VAL_all);
00159 default :
00160 }
00161 info.append("\"/>");
00162 return info.toString();
00163 }
00164 }