use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration in project elastic-job by dangdangdotcom.
the class RegistryCenterFactory method createCoordinatorRegistryCenter.
/**
* 创建注册中心.
*
* @param connectString 注册中心连接字符串
* @param namespace 注册中心命名空间
* @param digest 注册中心凭证
* @return 注册中心对象
*/
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) {
Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8);
if (digest.isPresent()) {
hasher.putString(digest.get(), Charsets.UTF_8);
}
HashCode hashCode = hasher.hash();
CoordinatorRegistryCenter result = REG_CENTER_REGISTRY.get(hashCode);
if (null != result) {
return result;
}
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace);
if (digest.isPresent()) {
zkConfig.setDigest(digest.get());
}
result = new ZookeeperRegistryCenter(zkConfig);
result.init();
REG_CENTER_REGISTRY.put(hashCode, result);
return result;
}
use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration in project elastic-job by dangdangdotcom.
the class RegistryCenterFactoryTest method assertCreateCoordinatorRegistryCenterFromCache.
@Test
public void assertCreateCoordinatorRegistryCenterFromCache() throws ReflectiveOperationException {
RegistryCenterFactory.createCoordinatorRegistryCenter(getConnectionString(), "otherNamespace", Optional.<String>absent());
ZookeeperConfiguration zkConfig = getZookeeperConfiguration(RegistryCenterFactory.createCoordinatorRegistryCenter(getConnectionString(), "otherNamespace", Optional.<String>absent()));
assertThat(zkConfig.getNamespace(), is("otherNamespace"));
assertNull(zkConfig.getDigest());
}
use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration in project elastic-job by dangdangdotcom.
the class RegistryCenterFactoryTest method getZookeeperConfiguration.
private ZookeeperConfiguration getZookeeperConfiguration(final CoordinatorRegistryCenter regCenter) throws ReflectiveOperationException {
Method method = ZookeeperRegistryCenter.class.getDeclaredMethod("getZkConfig");
method.setAccessible(true);
return (ZookeeperConfiguration) method.invoke(regCenter);
}
Aggregations