use of com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter 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.base.CoordinatorRegistryCenter 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.base.CoordinatorRegistryCenter in project elastic-job by dangdangdotcom.
the class JavaMain method main.
// CHECKSTYLE:OFF
public static void main(final String[] args) throws IOException {
// CHECKSTYLE:ON
EmbedZookeeperServer.start(EMBED_ZOOKEEPER_PORT);
CoordinatorRegistryCenter regCenter = setUpRegistryCenter();
JobEventConfiguration jobEventConfig = new JobEventRdbConfiguration(setUpEventTraceDataSource());
setUpSimpleJob(regCenter, jobEventConfig);
setUpDataflowJob(regCenter, jobEventConfig);
setUpScriptJob(regCenter, jobEventConfig);
}
use of com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter 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;
}
Aggregations