use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project elastic-job by dangdangdotcom.
the class Bootstrap method main.
/**
* 启动入口.
*
* @param args 命令行参数无需传入
* @throws InterruptedException 线程中断异常
*/
// CHECKSTYLE:OFF
public static void main(final String[] args) throws InterruptedException {
// CHECKSTYLE:ON
CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(BootstrapEnvironment.getInstance().getZookeeperConfiguration());
regCenter.init();
final ZookeeperElectionService electionService = new ZookeeperElectionService(BootstrapEnvironment.getInstance().getFrameworkHostPort(), (CuratorFramework) regCenter.getRawClient(), HANode.ELECTION_NODE, new SchedulerElectionCandidate(regCenter));
electionService.start();
final CountDownLatch latch = new CountDownLatch(1);
latch.await();
Runtime.getRuntime().addShutdownHook(new Thread("shutdown-hook") {
@Override
public void run() {
electionService.stop();
latch.countDown();
}
});
}
use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project elastic-job by dangdangdotcom.
the class JavaMain method setUpRegistryCenter.
private static CoordinatorRegistryCenter setUpRegistryCenter() {
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(ZOOKEEPER_CONNECTION_STRING, JOB_NAMESPACE);
CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig);
result.init();
return result;
}
use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter 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.ZookeeperRegistryCenter in project loc-framework by lord-of-code.
the class LocElasticJobAutoConfiguration method registerCenter.
private ZookeeperRegistryCenter registerCenter(LocElasticJobProperties elasticJobProperties) {
ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(elasticJobProperties.getServerList(), elasticJobProperties.getNamespace());
BeanUtils.copyProperties(elasticJobProperties, zookeeperConfiguration, "serverLists", "namespace");
ZookeeperRegistryCenter registryCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
registryCenter.init();
return registryCenter;
}
use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project loc-framework by lord-of-code.
the class LocElasticJobAutoConfiguration method init.
private void init() {
LocElasticJobProperties elasticJobProperties = resolverJobProperties();
String[] jobs = this.applicationContext.getBeanNamesForAnnotation(LocElasticJob.class);
ZookeeperRegistryCenter registryCenter = registerCenter(elasticJobProperties);
JobEventConfiguration jobEventConfiguration = Optional.ofNullable(Strings.emptyToNull(elasticJobProperties.getDataSource())).map(s -> new JobEventRdbConfiguration(applicationContext.getBean(s + "Ds", DataSource.class))).orElse(null);
createBean(registryCenter, jobEventConfiguration, jobs);
}
Aggregations