use of com.mongodb.internal.connection.MultiServerCluster in project LinkAgent by shulieTech.
the class MongoDBMongoClientDelegateConstructorInterceptor method check.
/**
* 判断是否影子库
*/
private void check(Object baseCluster, Mongo businessMongo) {
List<ServerAddress> addressList;
if (baseCluster instanceof SingleServerCluster) {
addressList = ((SingleServerCluster) baseCluster).getSettings().getHosts();
} else {
addressList = ((MultiServerCluster) baseCluster).getSettings().getHosts();
}
for (Map.Entry<String, ShadowDatabaseConfig> entry : GlobalConfig.getInstance().getShadowDatasourceConfigs().entrySet()) {
String businessUrl = entry.getValue().getUrl();
for (ServerAddress address : addressList) {
if (businessUrl != null && businessUrl.contains(address.toString())) {
if (!MongoClientHolder.mongoClientMap.containsKey(address.toString())) {
MongoClientHolder.mongoIntegerMap.put(businessMongo, 2);
break;
} else {
throw new PressureMeasureError("配置了相同地址的的影子库!");
}
}
}
}
for (ServerAddress address : addressList) {
ShadowDatabaseConfig shadowDatabaseConfig = GlobalConfig.getInstance().getShadowDatabaseConfig(address.toString());
if (shadowDatabaseConfig == null) {
continue;
}
if (!shadowDatabaseConfig.isShadowTable()) {
continue;
}
Map<String, String> map = shadowDatabaseConfig.getBusinessShadowTables();
if (null != map && map.size() > 0) {
MongoClientHolder.mongoIntegerMap.put(businessMongo, 1);
MongoClientHolder.mongoTableMappingMap.put(businessMongo, map);
break;
}
}
}
Aggregations