當前位置: 首頁>>代碼示例>>Java>>正文


Java CuratorFramework.start方法代碼示例

本文整理匯總了Java中org.apache.curator.framework.CuratorFramework.start方法的典型用法代碼示例。如果您正苦於以下問題:Java CuratorFramework.start方法的具體用法?Java CuratorFramework.start怎麽用?Java CuratorFramework.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.curator.framework.CuratorFramework的用法示例。


在下文中一共展示了CuratorFramework.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

示例3: setUp

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    Configurator
        .initialize("FastMQ", Thread.currentThread().getContextClassLoader(), "log4j2.xml");
    Log log = new Log();
    LogSegment logSegment = new LogSegment();
    logSegment.setLedgerId(ledgerId);
    logSegment.setTimestamp(System.currentTimeMillis());
    log.setSegments(Collections.singletonList(logSegment));
    when(logInfoStorage.getLogInfo(any())).thenReturn(log);

    CuratorFramework curatorFramework = CuratorFrameworkFactory
        .newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
    curatorFramework.start();
    asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
    offsetStorage = new ZkOffsetStorageImpl(logInfoStorage, asyncCuratorFramework);
}
 
開發者ID:aCoder2013,項目名稱:fastmq,代碼行數:18,代碼來源:ZkOffsetStorageImplTest.java

示例4: checkAndGetZK

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
/**
 * 檢查ZooKeeper的連接狀態和它的Znode目錄樹
 *
 * @param
 * @return
 */
public static CuratorFramework checkAndGetZK() {
    CuratorFramework client;
    try {
        RetryPolicy retryPolicy =
                new ExponentialBackoffRetry(configuration.ZK_RETRY_INTERVAL, configuration.ZK_RETRY_TIMES);
        client = CuratorFrameworkFactory
                .newClient(configuration.ZK_CONNECT_STRING
                        , configuration.ZK_SESSION_TIMEOUT, configuration.ZK_INIT_TIMEOUT, retryPolicy);
        client.start();
        client.checkExists().forPath(ZNodeStaticSetting.TASKS_PATH);
        client.checkExists().forPath(ZNodeStaticSetting.MANAGERS_PATH);
        client.checkExists().forPath(ZNodeStaticSetting.WORKERS_PATH);
        client.checkExists().forPath(ZNodeStaticSetting.FILTERS_ROOT);
    } catch (Throwable e) {
        client = null;
        logger.error(e.getMessage());
    }
    return client;
}
 
開發者ID:xiongbeer,項目名稱:Cobweb,代碼行數:26,代碼來源:SelfTest.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: 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

示例7: get

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
@Override
public CuratorFramework get() {
    String quorum = zookeeperConfig.getQuorum();
    String statsPath = zookeeperConfig.getPropertyServicePath();
    String connectionString = quorum + (statsPath == null ? "" : statsPath);

    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

    LOGGER.info("Initiating Curator connection to Zookeeper using: [{}]", connectionString);
    // Use chroot so all subsequent paths are below /stroom-stats to avoid conflicts with hbase/zookeeper/kafka etc.
    CuratorFramework client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy);
    client.start();

    try {
        // Ensure the chrooted root path exists (i.e. /stroom-stats)
        Stat stat = client.checkExists().forPath("/");
        if (stat == null) {
            LOGGER.info("Creating chroot-ed root node inside " + statsPath);
            client.create().forPath("/");
        }
    } catch (Exception e) {
        throw new RuntimeException("Error connecting to zookeeper using connection String: " + connectionString, e);
    }
    return client;
}
 
開發者ID:gchq,項目名稱:stroom-stats,代碼行數:26,代碼來源:StroomPropertyServiceCuratorFrameworkProvider.java

示例8: init

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
private void init(){
	CuratorFramework client = CuratorFrameworkFactory.newClient(zooKeeperUrl, new RetryForever(1000));
	leaderLatch = new LeaderLatch(client, "/EasyTransMasterSelector"+"/" + applicationName);
	try {
		client.start();
		leaderLatch.start();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:QNJR-GROUP,項目名稱:EasyTransaction,代碼行數:11,代碼來源:ZooKeeperMasterSelectorImpl.java

示例9: makeStartedCuratorClient

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
CuratorFramework makeStartedCuratorClient(String connectionString) {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(2000, 6, 2000);
    CuratorFramework client = CuratorFrameworkFactory.
            builder().connectString(connectionString)
            .retryPolicy(retryPolicy)
            .build();
    client.start();
    return client;
}
 
開發者ID:networknt,項目名稱:light-tram-4j,代碼行數:10,代碼來源:CdcServerStartupHookProvider.java

示例10: startAndBlock

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
private static void startAndBlock(CuratorFramework c) {
    c.start();

    tryIt(() -> {
        if(!c.getZookeeperClient().blockUntilConnectedOrTimedOut()) {
            throw new IOException("Did not connect in time: " + c.getZookeeperClient().getConnectionTimeoutMs() + " ms");
        }
    });
}
 
開發者ID:mcmoe,項目名稱:zoomap,代碼行數:10,代碼來源:ZooMap.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: testMultiPath

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
@Test
public void     testMultiPath() throws Exception
{
  Timing                  timing = new Timing();
  ChildReaper             reaper = null;
  CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
  try
  {
    client.start();

    for ( int i = 0; i < 10; ++i )
    {
      client.create().creatingParentsIfNeeded().forPath("/test1/" + Integer.toString(i));
      client.create().creatingParentsIfNeeded().forPath("/test2/" + Integer.toString(i));
      client.create().creatingParentsIfNeeded().forPath("/test3/" + Integer.toString(i));
    }

    reaper = new ChildReaper(client, "/test2", Reaper.Mode.REAP_UNTIL_DELETE, 1);
    reaper.start();
    reaper.addPath("/test1");

    timing.forWaiting().sleepABit();

    Stat    stat = client.checkExists().forPath("/test1");
    Assert.assertEquals(stat.getNumChildren(), 0);
    stat = client.checkExists().forPath("/test2");
    Assert.assertEquals(stat.getNumChildren(), 0);
    stat = client.checkExists().forPath("/test3");
    Assert.assertEquals(stat.getNumChildren(), 10);
  }
  finally
  {
    CloseableUtils.closeQuietly(reaper);
    CloseableUtils.closeQuietly(client);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:37,代碼來源:TestChildReaper.java

示例13: getClient

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
/**
 * 獲取ZK客戶端
 * @param zkServerAddress
 * @return
 */
public static CuratorFramework getClient(String zkServerAddress){
    if(zkServerAddress == null || zkServerAddress.trim().length() == 0){
        return null;
    }
    CuratorFramework client = clients.get(zkServerAddress);
    if(client==null){
        lock.lock();
        try {
            if(!clients.containsKey(zkServerAddress)) {
                client = CuratorFrameworkFactory.newClient(
                        zkServerAddress,
                        DEFAULT_SESSION_TIMEOUT_MS,
                        DEFAULT_CONNECTION_TIMEOUT_MS,
                        new RetryNTimes(10, 5000)
                );
                client.start();
                clients.putIfAbsent(zkServerAddress,client);
            }else{
                client = clients.get(zkServerAddress);
            }
        }finally {
            lock.unlock();
        }
    }
    return client;

}
 
開發者ID:all4you,項目名稱:redant,代碼行數:33,代碼來源:ZkClient.java

示例14: 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

示例15: testSomeNodes

import org.apache.curator.framework.CuratorFramework; //導入方法依賴的package包/類
@Test
public void     testSomeNodes() throws Exception
{

  Timing                  timing = new Timing();
  ChildReaper             reaper = null;
  CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
  try
  {
    client.start();

    Random              r = new Random();
    int                 nonEmptyNodes = 0;
    for ( int i = 0; i < 10; ++i )
    {
      client.create().creatingParentsIfNeeded().forPath("/test/" + Integer.toString(i));
      if ( r.nextBoolean() )
      {
        client.create().forPath("/test/" + Integer.toString(i) + "/foo");
        ++nonEmptyNodes;
      }
    }

    reaper = new ChildReaper(client, "/test", Reaper.Mode.REAP_UNTIL_DELETE, 1);
    reaper.start();

    timing.forWaiting().sleepABit();

    Stat    stat = client.checkExists().forPath("/test");
    Assert.assertEquals(stat.getNumChildren(), nonEmptyNodes);
  }
  finally
  {
    CloseableUtils.closeQuietly(reaper);
    CloseableUtils.closeQuietly(client);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:38,代碼來源:TestChildReaper.java


注:本文中的org.apache.curator.framework.CuratorFramework.start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。