use of com.alibaba.otter.common.push.supplier.DatasourceChangeCallback 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.DatasourceChangeCallback 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