use of com.vip.saturn.job.sharding.NamespaceShardingManager in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshNamespaceShardingListenerManagerMap.
/**
* 创建或者移除namespaceShardingManager.
*/
private void refreshNamespaceShardingListenerManagerMap() {
Iterator<Entry<String, ZkCluster>> iterator = zkClusterMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, ZkCluster> next = iterator.next();
ZkCluster zkCluster = next.getValue();
ArrayList<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
if (regCenterConfList == null) {
continue;
}
for (RegistryCenterConfiguration conf : regCenterConfList) {
String nns = conf.getNameAndNamespace();
if (!namespaceShardingListenerManagerMap.containsKey(nns)) {
if (isZKClusterCanBeComputed(conf.getZkClusterKey())) {
createNamespaceShardingManager(conf, nns);
}
} else {
NamespaceShardingManager namespaceShardingManager = namespaceShardingListenerManagerMap.get(nns);
if (!isZKClusterCanBeComputed(conf.getZkClusterKey())) {
namespaceShardingManager.stopWithCurator();
namespaceShardingListenerManagerMap.remove(nns);
}
}
}
}
}
use of com.vip.saturn.job.sharding.NamespaceShardingManager in project Saturn by vipshop.
the class RegistryCenterServiceImpl method createNamespaceShardingManager.
private void createNamespaceShardingManager(RegistryCenterConfiguration conf, String nns) {
try {
log.info("Start NamespaceShardingManager {}", nns);
String namespace = conf.getNamespace();
String digest = conf.getDigest();
CuratorFramework client = curatorRepository.connect(conf.getZkAddressList(), namespace, digest);
if (client == null) {
log.warn("fail to connect to zk during create NamespaceShardingManager");
return;
}
NamespaceShardingManager namespaceShardingManager = null;
try {
namespaceShardingManager = new NamespaceShardingManager(client, namespace, generateShardingLeadershipHostValue(), reportAlarmService, updateJobConfigService);
namespaceShardingManager.start();
if (namespaceShardingListenerManagerMap.putIfAbsent(nns, namespaceShardingManager) != null) {
// 已经存在,则关闭当前的client
try {
namespaceShardingManager.stopWithCurator();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
} else {
log.info("Done starting NamespaceShardingManager {}", nns);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
if (namespaceShardingManager != null) {
try {
namespaceShardingManager.stop();
} catch (Exception e2) {
log.error(e2.getMessage(), e2);
}
}
client.close();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations