1 24 25 package org.objectweb.cjdbc.controller.virtualdatabase.protocol; 26 27 import java.io.Serializable ; 28 import java.util.ArrayList ; 29 import java.util.List ; 30 31 import org.objectweb.cjdbc.common.i18n.Translate; 32 import org.objectweb.cjdbc.common.jmx.JmxConstants; 33 import org.objectweb.cjdbc.common.shared.BackendInfo; 34 import org.objectweb.cjdbc.controller.jmx.RmiConnector; 35 import org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase; 36 37 44 public class VirtualDatabaseConfiguration implements Serializable 45 { 46 private static final long serialVersionUID = -4753828540599620782L; 47 48 private String controllerName; 49 private String controllerJmxName; 50 private String vdbName; 51 private String groupName = null; 52 private ArrayList vLogins; 53 private int schedulerRAIDbLevel; 54 private int loadBalancerRAIDbLevel; 55 private ArrayList backends; 56 57 private String rmiHostname; 59 private String rmiPort; 60 61 64 public String getControllerName() 65 { 66 return controllerName; 67 } 68 69 74 public String getControllerJmxName() 75 { 76 return controllerJmxName; 77 } 78 79 85 public VirtualDatabaseConfiguration(DistributedVirtualDatabase dvdb) 86 { 87 this.controllerName = dvdb.getControllerName(); 88 this.controllerJmxName = dvdb.viewOwningController(); 89 this.vdbName = dvdb.getVirtualDatabaseName(); 90 this.groupName = dvdb.getGroupName(); 91 this.vLogins = dvdb.getAuthenticationManager().getVirtualLogins(); 92 this.schedulerRAIDbLevel = dvdb.getRequestManager().getScheduler() 93 .getRAIDbLevel(); 94 this.loadBalancerRAIDbLevel = dvdb.getRequestManager().getLoadBalancer() 95 .getRAIDbLevel(); 96 this.backends = dvdb.getBackendsInfo(dvdb.getBackends()); 97 98 List connectors = RmiConnector.getRmiConnectors(); 99 if (connectors.size() > 0) 100 { 101 RmiConnector rmi = (RmiConnector) connectors.get(0); 102 rmiHostname = rmi.getHostName(); 103 rmiPort = String.valueOf(rmi.getPort()); 104 } 105 else 106 { 107 rmiHostname = controllerName.substring(0, controllerName.indexOf(":")); 108 rmiPort = String.valueOf(JmxConstants.DEFAULT_JMX_RMI_PORT); 109 } 110 } 111 112 115 public String getRmiHostname() 116 { 117 return rmiHostname; 118 } 119 120 123 public String getRmiPort() 124 { 125 return rmiPort; 126 } 127 128 135 public boolean isCompatible(DistributedVirtualDatabase localDvdb) 136 { 137 try 138 { 139 if (controllerName.equals(localDvdb.getControllerName())) 140 { 141 localDvdb.logger 142 .warn(Translate 143 .get("virtualdatabase.distributed.configuration.checking.duplicate.controller.name")); 144 return false; 145 } 146 147 if (!vdbName.equals(localDvdb.getVirtualDatabaseName())) 149 { 150 localDvdb.logger 151 .warn(Translate 152 .get("virtualdatabase.distributed.configuration.checking.mismatch.name")); 153 return false; 154 } 155 if (!groupName.equals(localDvdb.getGroupName())) 156 { 157 localDvdb.logger 158 .warn(Translate 159 .get("virtualdatabase.distributed.configuration.checking.mismatch.groupname")); 160 return false; 161 } 162 163 if (!vLogins.containsAll(localDvdb.getAuthenticationManager() 167 .getVirtualLogins()) 168 || !localDvdb.getAuthenticationManager().getVirtualLogins() 169 .containsAll(vLogins)) 170 { 171 localDvdb.logger 172 .warn(Translate 173 .get("virtualdatabase.distributed.configuration.checking.mismatch.vlogins")); 174 return false; 175 } 176 177 if (schedulerRAIDbLevel != localDvdb.getRequestManager().getScheduler() 179 .getRAIDbLevel()) 180 { 181 localDvdb.logger 182 .warn(Translate 183 .get("virtualdatabase.distributed.configuration.checking.mismatch.scheduler")); 184 return false; 185 } 186 187 if (loadBalancerRAIDbLevel != localDvdb.getRequestManager() 188 .getLoadBalancer().getRAIDbLevel()) 189 { 190 localDvdb.logger 191 .warn(Translate 192 .get("virtualdatabase.distributed.configuration.checking.mismatch.loadbalancer")); 193 return false; 194 } 195 196 int size = backends.size(); 198 for (int i = 0; i < size; i++) 199 { 200 BackendInfo b = (BackendInfo) backends.get(i); 201 if (!localDvdb.isCompatibleBackend(b)) 202 { 203 localDvdb.logger 204 .warn(Translate 205 .get( 206 "virtualdatabase.distributed.configuration.checking.mismatch.backend.shared", 207 b.getName())); 208 return false; 209 } 210 } 211 212 return true; 214 } 215 catch (Exception e) 216 { 217 localDvdb.logger.error(Translate 218 .get("virtualdatabase.distributed.configuration.checking.error"), e); 219 return false; 220 } 221 } 222 223 } | Popular Tags |