use of com.alibaba.otter.common.push.supplier.DatasourceInfo in project otter by alibaba.
the class MediaPushDataSource method init.
public synchronized void init() {
if (!dataMediaType.isMysql()) {
throw new UnsupportedOperationException("currently only support mysql type");
}
if (delegate != null) {
return;
}
if (dataSourceSupplier == null) {
dataSourceSupplier = MediaDatasourceSupplier.newInstance(dbGroupKey);
dataSourceSupplier.start();
dataSourceSupplier.addSwtichCallback(new DatasourceChangeCallback() {
public void masterChanged(DatasourceInfo newMaster) {
String newUrl = buildMysqlUrl(newMaster.getAddress().getAddress().getHostAddress(), newMaster.getAddress().getPort());
try {
((BasicDataSource) delegate).close();
DataSource newDelegate = doCreateDataSource(newUrl);
delegate = newDelegate;
} catch (SQLException e) {
logger.error("switch master error with url : " + originalUrl, e);
}
}
});
}
DatasourceInfo datasourceInfo = dataSourceSupplier.fetchMaster();
String url = buildMysqlUrl(datasourceInfo.getAddress().getAddress().getHostAddress(), datasourceInfo.getAddress().getPort());
delegate = doCreateDataSource(url);
}
use of com.alibaba.otter.common.push.supplier.DatasourceInfo in project otter by alibaba.
the class MediaDatasourceSupplier method parse.
private HaDatasourceInfo parse(String matrixStr) {
HaDatasourceInfo haInfo = new HaDatasourceInfo();
Map jsonMap = JsonUtils.unmarshalFromString(matrixStr, HashMap.class);
String masterAddress = (String) jsonMap.get("master");
if (masterAddress != null) {
DatasourceInfo master = new DatasourceInfo();
master.setAddress(parseAddress(masterAddress));
haInfo.setMaster(master);
}
String slaveAddress = (String) jsonMap.get("master");
if (slaveAddress != null) {
DatasourceInfo slave = new DatasourceInfo();
slave.setAddress(parseAddress(slaveAddress));
haInfo.getSlavers().add(slave);
}
return haInfo;
}
use of com.alibaba.otter.common.push.supplier.DatasourceInfo in project otter by alibaba.
the class MediaHAController method start.
public void start() throws CanalHAException {
super.start();
if (this.supplier == null) {
validate();
this.supplier = MediaDatasourceSupplier.newInstance(group);
}
if (!this.supplier.isStart()) {
this.supplier.start();
}
DatasourceInfo fetched = this.supplier.fetchMaster();
AuthenticationInfo masterFetched = AuthenticationInfoUtils.createFrom(fetched);
log.info(String.format("medialHAController started for goup:[%s], and first auth info is : [%s]", this.group, masterFetched));
this.availableAuthenticationInfo = customInfoIfNecessay(masterFetched);
log.info(String.format("medialHAController customed for goup:[%s], and first auth info is : [%s]", this.group, this.availableAuthenticationInfo));
this.supplier.addSwtichCallback(new DatasourceChangeCallback() {
@Override
public void masterChanged(DatasourceInfo newMaster) {
AuthenticationInfo newAuthenticationInfo = AuthenticationInfoUtils.createFrom(newMaster);
switchEventSource(newAuthenticationInfo);
}
});
}
Aggregations