use of com.alibaba.cobar.config.model.DataNodeConfig in project cobar by alibaba.
the class MySQLDetectorFactory method make.
public MySQLDetector make(MySQLHeartbeat heartbeat) throws IOException {
SocketChannel channel = openSocketChannel();
DataSourceConfig dsc = heartbeat.getSource().getConfig();
DataNodeConfig dnc = heartbeat.getSource().getNode().getConfig();
MySQLDetector detector = new MySQLDetector(channel);
detector.setHost(dsc.getHost());
detector.setPort(dsc.getPort());
detector.setUser(dsc.getUser());
detector.setPassword(dsc.getPassword());
detector.setSchema(dsc.getDatabase());
detector.setHeartbeatTimeout(dnc.getHeartbeatTimeout());
detector.setHeartbeat(heartbeat);
postConnect(detector, CobarServer.getInstance().getConnector());
return detector;
}
use of com.alibaba.cobar.config.model.DataNodeConfig in project cobar by alibaba.
the class XMLSchemaLoader method loadDataNodes.
private void loadDataNodes(Element root) {
NodeList list = root.getElementsByTagName("dataNode");
for (int i = 0, n = list.getLength(); i < n; i++) {
Element element = (Element) list.item(i);
String dnNamePrefix = element.getAttribute("name");
List<DataNodeConfig> confList = new ArrayList<DataNodeConfig>();
try {
Element dsElement = findPropertyByName(element, "dataSource");
if (dsElement == null) {
throw new NullPointerException("dataNode xml Element with name of " + dnNamePrefix + " has no dataSource Element");
}
NodeList dataSourceList = dsElement.getElementsByTagName("dataSourceRef");
String[][] dataSources = new String[dataSourceList.getLength()][];
for (int j = 0, m = dataSourceList.getLength(); j < m; ++j) {
Element ref = (Element) dataSourceList.item(j);
String dsString = ref.getTextContent();
dataSources[j] = SplitUtil.split(dsString, ',', '$', '-', '[', ']');
}
if (dataSources.length <= 0) {
throw new ConfigException("no dataSourceRef defined!");
}
for (String[] dss : dataSources) {
if (dss.length != dataSources[0].length) {
throw new ConfigException("dataSource number not equals!");
}
}
for (int k = 0, limit = dataSources[0].length; k < limit; ++k) {
StringBuilder dsString = new StringBuilder();
for (int dsIndex = 0; dsIndex < dataSources.length; ++dsIndex) {
if (dsIndex > 0) {
dsString.append(',');
}
dsString.append(dataSources[dsIndex][k]);
}
DataNodeConfig conf = new DataNodeConfig();
ParameterMapping.mapping(conf, ConfigUtil.loadElements(element));
confList.add(conf);
switch(k) {
case 0:
conf.setName((limit == 1) ? dnNamePrefix : dnNamePrefix + "[" + k + "]");
break;
default:
conf.setName(dnNamePrefix + "[" + k + "]");
break;
}
conf.setDataSource(dsString.toString());
}
} catch (Exception e) {
throw new ConfigException("dataNode " + dnNamePrefix + " define error", e);
}
for (DataNodeConfig conf : confList) {
if (dataNodes.containsKey(conf.getName())) {
throw new ConfigException("dataNode " + conf.getName() + " duplicated!");
}
dataNodes.put(conf.getName(), conf);
}
}
}
use of com.alibaba.cobar.config.model.DataNodeConfig in project cobar by alibaba.
the class ConfigInitializer method initDataNodes.
private Map<String, MySQLDataNode> initDataNodes(ConfigLoader configLoader) {
Map<String, DataNodeConfig> nodeConfs = configLoader.getDataNodes();
Map<String, MySQLDataNode> nodes = new HashMap<String, MySQLDataNode>(nodeConfs.size());
for (DataNodeConfig conf : nodeConfs.values()) {
MySQLDataNode dataNode = getDataNode(conf, configLoader);
if (nodes.containsKey(dataNode.getName())) {
throw new ConfigException("dataNode " + dataNode.getName() + " duplicated!");
}
nodes.put(dataNode.getName(), dataNode);
}
return nodes;
}
Aggregations