Search in sources :

Example 6 with ZookeeperConfiguration

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;
}
Also used : ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode) ZookeeperConfiguration(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration) CoordinatorRegistryCenter(com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)

Example 7 with ZookeeperConfiguration

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());
}
Also used : ZookeeperConfiguration(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration) AbstractEmbedZookeeperBaseTest(com.dangdang.ddframe.job.lite.lifecycle.AbstractEmbedZookeeperBaseTest) Test(org.junit.Test)

Example 8 with ZookeeperConfiguration

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);
}
Also used : Method(java.lang.reflect.Method) ZookeeperConfiguration(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration)

Aggregations

ZookeeperConfiguration (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration)8 Test (org.junit.Test)4 AbstractEmbedZookeeperBaseTest (com.dangdang.ddframe.job.lite.lifecycle.AbstractEmbedZookeeperBaseTest)3 CoordinatorRegistryCenter (com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)2 ZookeeperRegistryCenter (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter)2 HashCode (com.google.common.hash.HashCode)1 Hasher (com.google.common.hash.Hasher)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1