Search in sources :

Example 1 with CoordinatorRegistryCenter

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();
        }
    });
}
Also used : ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) ZookeeperElectionService(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperElectionService) CountDownLatch(java.util.concurrent.CountDownLatch) SchedulerElectionCandidate(com.dangdang.ddframe.job.cloud.scheduler.ha.SchedulerElectionCandidate) CoordinatorRegistryCenter(com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)

Example 2 with CoordinatorRegistryCenter

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

Example 3 with CoordinatorRegistryCenter

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);
}
Also used : JobEventRdbConfiguration(com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration) JobEventConfiguration(com.dangdang.ddframe.job.event.JobEventConfiguration) CoordinatorRegistryCenter(com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)

Example 4 with CoordinatorRegistryCenter

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;
}
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)

Aggregations

CoordinatorRegistryCenter (com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)4 ZookeeperRegistryCenter (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter)3 ZookeeperConfiguration (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration)2 SchedulerElectionCandidate (com.dangdang.ddframe.job.cloud.scheduler.ha.SchedulerElectionCandidate)1 JobEventConfiguration (com.dangdang.ddframe.job.event.JobEventConfiguration)1 JobEventRdbConfiguration (com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration)1 ZookeeperElectionService (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperElectionService)1 HashCode (com.google.common.hash.HashCode)1 Hasher (com.google.common.hash.Hasher)1 CountDownLatch (java.util.concurrent.CountDownLatch)1