当前位置: 首页>>代码示例>>Java>>正文


Java CuratorFramework.blockUntilConnected方法代码示例

本文整理汇总了Java中org.apache.curator.framework.CuratorFramework.blockUntilConnected方法的典型用法代码示例。如果您正苦于以下问题:Java CuratorFramework.blockUntilConnected方法的具体用法?Java CuratorFramework.blockUntilConnected怎么用?Java CuratorFramework.blockUntilConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.framework.CuratorFramework的用法示例。


在下文中一共展示了CuratorFramework.blockUntilConnected方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildConnection

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
private static CuratorFramework buildConnection(String url) {
    CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));

    // start connection
    curatorFramework.start();
    // wait 3 second to establish connect
    try {
        curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
        if (curatorFramework.getZookeeperClient().isConnected()) {
            return curatorFramework.usingNamespace("");
        }
    } catch (InterruptedException ignored) {
        Thread.currentThread().interrupt();
    }

    // fail situation
    curatorFramework.close();
    throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:20,代码来源:ZktoXmlMain.java

示例2: createConnection

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
private static CuratorFramework createConnection() {
       String url= ZkConfig.getInstance().getZkURL();

    CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));

    // start connection
    curatorFramework.start();
    // wait 3 second to establish connect
    try {
        curatorFramework.blockUntilConnected(3, TimeUnit.SECONDS);
        if (curatorFramework.getZookeeperClient().isConnected()) {
            return curatorFramework;
        }
    } catch (InterruptedException ignored) {
        Thread.currentThread().interrupt();
    }

    // fail situation
    curatorFramework.close();
    throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:22,代码来源:ZKUtils.java

示例3: assertPersistEphemeralSequential

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test
public void assertPersistEphemeralSequential() throws Exception {
    zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
    zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    List<String> actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertThat(actual.size(), is(2));
    for (String each : actual) {
        assertThat(each, startsWith("test_ephemeral_sequential"));
    }
    zkRegCenter.close();
    actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertTrue(actual.isEmpty());
    zkRegCenter.init();
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:18,代码来源:ZookeeperRegistryCenterModifyTest.java

示例4: assertContend

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test
@Ignore
public void assertContend() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    ZookeeperElectionService service = new ZookeeperElectionService(HOST_AND_PORT, client, ELECTION_PATH, electionCandidate);
    service.start();
    ElectionCandidate anotherElectionCandidate = mock(ElectionCandidate.class);
    CuratorFramework anotherClient = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    ZookeeperElectionService anotherService = new ZookeeperElectionService("ANOTHER_CLIENT:8899", anotherClient, ELECTION_PATH, anotherElectionCandidate);
    anotherClient.start();
    anotherClient.blockUntilConnected();
    anotherService.start();
    KillSession.kill(client.getZookeeperClient().getZooKeeper(), EmbedTestingServer.getConnectionString());
    service.stop();
    verify(anotherElectionCandidate).startLeadership();
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:19,代码来源:ZookeeperElectionServiceTest.java

示例5: testZkHealth

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test
public void testZkHealth() throws Exception {

    final CuratorFramework client = newClient(zk.getConnectString(), new RetryOneTime(100));
    client.start();
    client.blockUntilConnected();

    final HealthCheck check = new KafkaHealthCheck(client);
    final HealthCheck.Result res = check.execute();
    assertFalse(res.isHealthy());
    assertTrue(res.getMessage().contains("Error fetching kafka broker list"));

    client.createContainers("/brokers/ids");

    final HealthCheck.Result res2 = check.execute();
    assertFalse(res2.isHealthy());
    assertEquals("No Kafka brokers are connected.", res2.getMessage());

    client.createContainers("/brokers/ids/1");

    final HealthCheck.Result res3 = check.execute();
    assertTrue(res3.isHealthy());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:24,代码来源:KafkaHealthCheckTest.java

示例6: testZkHealth

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test
public void testZkHealth() throws Exception {
    final CuratorFramework client = newClient(zk.getConnectString(), new RetryOneTime(100));
    client.start();
    client.blockUntilConnected();

    final HealthCheck check = new ZookeeperHealthCheck(client);
    final HealthCheck.Result res = check.execute();
    assertFalse(res.isHealthy());
    assertEquals("Zookeeper not properly initialized", res.getMessage());

    client.createContainers(ZNODE_COORDINATION);

    final HealthCheck.Result res2 = check.execute();
    assertTrue(res2.isHealthy());
}
 
开发者ID:trellis-ldp,项目名称:trellis-rosid,代码行数:17,代码来源:ZookeeperHealthCheckTest.java

示例7: createConnection

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
private static CuratorFramework createConnection() {
    String url = ZkConfig.getInstance().getZkURL();
    CuratorFramework framework = CuratorFrameworkFactory.newClient(url, new ExponentialBackoffRetry(100, 6));
    // start connection
    framework.start();
    // wait 3 second to establish connect
    try {
        framework.blockUntilConnected(3, TimeUnit.SECONDS);
        if (framework.getZookeeperClient().isConnected()) {
            LOGGER.info("CuratorFramework createConnection success");
            return framework;
        }
    } catch (InterruptedException ignored) {
        LOGGER.info("CuratorFramework createConnection error", ignored);
        Thread.currentThread().interrupt();
    }
    // fail situation
    framework.close();
    throw new RuntimeException("failed to connect to zookeeper service : " + url);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:21,代码来源:ZKUtils.java

示例8: curatorFramework

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean
public CuratorFramework curatorFramework(AlbedoRpcProperties albedoRpcProperties, RetryPolicy retryPolicy) throws InterruptedException {
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
    String namespace = environment.getProperty("albedo.rpc.namespace", albedoRpcProperties.getNamespace());
    AlbedoRpcProperties.Zookeeper zookeeper = albedoRpcProperties.getZookeeper();
    String connectString = environment.getProperty("albedo.rpc.zookeeper.connectString", zookeeper.getConnectString());
    Integer blockUntilConnectedWait = Integer.parseInt(environment.getProperty("albedo.rpc.zookeeper.blockUntilConnectedWait",
            zookeeper.getBlockUntilConnectedWait()+""));
    logger.info("CuratorFramework namespace {}", namespace);
    CuratorFramework curator = builder
            .retryPolicy(retryPolicy)
            .canBeReadOnly(true)
            .namespace(namespace)
            .connectString(connectString)
            .defaultData(null)
            .build();
    curator.blockUntilConnected(blockUntilConnectedWait,
            TimeUnit.SECONDS);
    curator.start();
    return curator;
}
 
开发者ID:somewhereMrli,项目名称:albedo-thrift,代码行数:23,代码来源:CommonAutoConfiguration.java

示例9: assertInitWithDigestSuccess

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test
public void assertInitWithDigestSuccess() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.builder()
        .connectString(EmbedTestingServer.getConnectionString())
        .retryPolicy(new RetryOneTime(2000))
        .authorization("digest", "digest:password".getBytes()).build();
    client.start();
    client.blockUntilConnected();
    assertThat(client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested"), is("deepNested".getBytes()));
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:11,代码来源:ZookeeperRegistryCenterForAuthTest.java

示例10: assertInitWithDigestFailure

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test(expected = NoAuthException.class)
public void assertInitWithDigestFailure() throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:8,代码来源:ZookeeperRegistryCenterForAuthTest.java

示例11: assertPersistEphemeral

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test
public void assertPersistEphemeral() throws Exception {
    zkRegCenter.persist("/persist", "persist_value");
    zkRegCenter.persistEphemeral("/ephemeral", "ephemeral_value");
    assertThat(zkRegCenter.get("/persist"), is("persist_value"));
    assertThat(zkRegCenter.get("/ephemeral"), is("ephemeral_value"));
    zkRegCenter.close();
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    assertThat(client.getData().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/persist"), is("persist_value".getBytes()));
    assertNull(client.checkExists().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/ephemeral"));
    zkRegCenter.init();
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:15,代码来源:ZookeeperRegistryCenterModifyTest.java

示例12: assertPersistSequential

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
@Test
public void assertPersistSequential() throws Exception {
    assertThat(zkRegCenter.persistSequential("/sequential/test_sequential", "test_value"), startsWith("/sequential/test_sequential"));
    assertThat(zkRegCenter.persistSequential("/sequential/test_sequential", "test_value"), startsWith("/sequential/test_sequential"));
    CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
    client.start();
    client.blockUntilConnected();
    List<String> actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
    assertThat(actual.size(), is(2));
    for (String each : actual) {
        assertThat(each, startsWith("test_sequential"));
        assertThat(zkRegCenter.get("/sequential/" + each), startsWith("test_value"));
    }
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:15,代码来源:ZookeeperRegistryCenterModifyTest.java

示例13: createNewCuratorInstance

import org.apache.curator.framework.CuratorFramework; //导入方法依赖的package包/类
/**
 * Create new curator instance based upon the provided config.
 *
 * @param config configuration object.
 * @param context context about who is creating the instance.
 * @return curator instance.
 */
public static CuratorFramework createNewCuratorInstance(final Map<String, Object> config, final String context) {
    // List of zookeeper hosts in the format of ["host1:2182", "host2:2181",..].
    final List<String> zkServers = (List<String>) config.get(CONFIG_SERVERS);

    Preconditions.checkArgument(!zkServers.isEmpty(), "Zookeepers servers are required");

    // Convert list of servers into comma deliminated string of servers.
    final String zkConnectionString = zkServers.stream()
        .collect(Collectors.joining(","));

    try {
        // Create new ThreadFactory with named threads.
        // TODO allow pushing in better naming.
        final ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat("[" + DynamicSpout.class.getSimpleName() + ":" + context + "] Curator Pool %d")
            .setDaemon(false)
            .build();

        // Use builder to create new curator
        final CuratorFramework curator = CuratorFrameworkFactory
            .builder()
            .connectString(zkConnectionString)
            .connectionTimeoutMs(getConnectionTimeoutMs(config))
            .sessionTimeoutMs(getSessionTimeoutMs(config))
            .retryPolicy(new RetryNTimes(getRetryAttempts(config), getRetryIntervalMs(config)))
            .threadFactory(threadFactory)
            .build();

        // Call start
        curator.start();

        // Block until connected
        curator.blockUntilConnected(
            getConnectionTimeoutMs(config),
            TimeUnit.MILLISECONDS
        );

        return curator;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:salesforce,项目名称:storm-dynamic-spout,代码行数:50,代码来源:CuratorFactory.java


注:本文中的org.apache.curator.framework.CuratorFramework.blockUntilConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。