use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class ReuseUtils method reuse.
public static <T> T reuse(String namespace, RegistryCenterService registryCenterService, CuratorRepository curatorRepository, ReuseCallBack<T> callBack) throws SaturnJobConsoleException {
try {
RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
if (registryCenterConfiguration == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace));
}
RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
if (registryCenterClient != null && registryCenterClient.isConnected()) {
CuratorFramework curatorClient = registryCenterClient.getCuratorClient();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorClient);
ThreadLocalCuratorClient.setCuratorClient(curatorClient);
return callBack.call(curatorFrameworkOp);
} else {
throw new SaturnJobConsoleException("Connect zookeeper failed");
}
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Throwable t) {
log.error(t.getMessage(), t);
throw new SaturnJobConsoleException(t);
} finally {
ThreadLocalCuratorClient.clear();
}
}
Aggregations