use of com.ctrip.framework.dal.cluster.client.database.ConnectionString in project dal by ctripcorp.
the class DatabaseShardImpl method initReadStrategy.
public void initReadStrategy() {
ClusterRouteStrategyConfig config = databaseShardConfig.getClusterConfig().getRouteStrategyConfig();
if (config == null || config.multiMaster()) {
return;
}
routeStrategy = (ReadStrategy) config.generate();
List<Database> databases = new ArrayList<>();
databases.addAll(masters);
databases.addAll(slaves);
Set<HostSpec> hostSpecs = new HashSet<>();
databases.forEach(database -> {
ConnectionString connString = database.getConnectionString();
HostSpec host = HostSpec.of(connString.getPrimaryHost(), connString.getPrimaryPort(), database.getZone(), database.isMaster());
hostToDataBase.putIfAbsent(host, database);
hostSpecs.add(host);
});
try {
routeStrategy.init(hostSpecs, new CaseInsensitiveProperties());
} catch (DalMetadataException error) {
throw new DalMetadataException(databaseShardConfig.getClusterConfig().getClusterName() + error.getMessage());
}
}
Aggregations