本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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();
}
示例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());
}
示例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());
}
示例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);
}
示例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;
}
示例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()));
}
示例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");
}
示例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();
}
示例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"));
}
}
示例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);
}
}