1 22 23 package org.continuent.sequoia.controller.loadbalancer.policies.createtable; 24 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 28 import org.continuent.sequoia.common.xml.DatabasesXmlTags; 29 import org.continuent.sequoia.common.xml.XmlComponent; 30 31 37 public class CreateTablePolicy implements XmlComponent 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 private HashMap ruleList = new HashMap (); 50 51 58 public void addRule(CreateTableRule rule) 59 { 60 ruleList.put(rule.getTableName(), rule); 61 } 62 63 68 public HashMap getRuleList() 69 { 70 return ruleList; 71 } 72 73 80 public CreateTableRule getTableRule(String tableName) 81 { 82 return (CreateTableRule) ruleList.get(tableName); 83 } 84 85 91 public CreateTableRule getDefaultRule() 92 { 93 return (CreateTableRule) ruleList.get(null); 94 } 95 96 102 public static final String getXmlValue(int policy) 103 { 104 switch (policy) 105 { 106 case RANDOM : 107 return DatabasesXmlTags.VAL_random; 108 case ROUND_ROBIN : 109 return DatabasesXmlTags.VAL_roundRobin; 110 case ALL : 111 return DatabasesXmlTags.VAL_all; 112 default : 113 return ""; 114 } 115 } 116 117 123 public String getXml() 124 { 125 StringBuffer info = new StringBuffer (); 126 for (Iterator iterator = ruleList.keySet().iterator(); iterator.hasNext();) 127 info.append(((CreateTableRule) ruleList.get(iterator.next())).getXml()); 128 return info.toString(); 129 } 130 131 } 132 | Popular Tags |