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


Java CuratorFrameworkFactory.newClient方法代码示例

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


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

示例1: setUp

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    zookeeper = new ZooKeeper("127.0.0.1:2181", 10000, event -> {
        if (event.getState() == Watcher.Event.KeeperState.SyncConnected) {
            System.out.println("Zookeeper connected.");
        } else {
            throw new RuntimeException("Error connecting to zookeeper");
        }
        latch.countDown();
    });
    latch.await();
    CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
    curatorFramework.start();
    AsyncCuratorFramework asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
    logInfoStorage = new LogInfoStorageImpl(asyncCuratorFramework);
}
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:18,代码来源:LogStorageImplTest.java

示例2: checkAndGetZK

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的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

示例3: assertPersistEphemeralSequential

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的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: createConnection

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的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

示例5: get

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的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

示例6: assertContend

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的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

示例7: ZookeeperOffsetHandler

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
public ZookeeperOffsetHandler(Properties props) {
	this.groupId = props.getProperty(ConsumerConfig.GROUP_ID_CONFIG);
	if (this.groupId == null) {
		throw new IllegalArgumentException("Required property '"
				+ ConsumerConfig.GROUP_ID_CONFIG + "' has not been set");
	}

	String zkConnect = props.getProperty("zookeeper.connect");
	if (zkConnect == null) {
		throw new IllegalArgumentException("Required property 'zookeeper.connect' has not been set");
	}

	// we use Curator's default timeouts
	int sessionTimeoutMs =  Integer.valueOf(props.getProperty("zookeeper.session.timeout.ms", "60000"));
	int connectionTimeoutMs = Integer.valueOf(props.getProperty("zookeeper.connection.timeout.ms", "15000"));

	// undocumented config options allowing users to configure the retry policy. (they are "flink." prefixed as they are no official kafka configs)
	int backoffBaseSleepTime = Integer.valueOf(props.getProperty("flink.zookeeper.base-sleep-time.ms", "100"));
	int backoffMaxRetries =  Integer.valueOf(props.getProperty("flink.zookeeper.max-retries", "10"));

	RetryPolicy retryPolicy = new ExponentialBackoffRetry(backoffBaseSleepTime, backoffMaxRetries);
	curatorClient = CuratorFrameworkFactory.newClient(zkConnect, sessionTimeoutMs, connectionTimeoutMs, retryPolicy);
	curatorClient.start();
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:25,代码来源:ZookeeperOffsetHandler.java

示例8: setup

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
@Before
public void setup() {
    try {
        zkServer = new TestingServerStarter().start();
    } catch (Exception e) {
        log.error("Error starting ZK server", e);
    }
    zkClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(),
            new ExponentialBackoffRetry(200, 10, 5000));
    zkClient.start();

    streamStore = StreamStoreFactory.createZKStore(zkClient, executor);
    TaskMetadataStore taskMetadataStore = TaskStoreFactory.createZKStore(zkClient, executor);
    hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig());
    segmentHelperMock = SegmentHelperMock.getSegmentHelperMock();
    connectionFactory = Mockito.mock(ConnectionFactory.class);
    streamMetadataTasks = new StreamMetadataTasks(streamStore, hostStore, taskMetadataStore, segmentHelperMock,
            executor, "host", connectionFactory);
}
 
开发者ID:pravega,项目名称:pravega,代码行数:20,代码来源:StreamTransactionMetadataTasksTest.java

示例9: ServiceRegistry

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
/**
 * <p>Retrieves the Zookeeper service URI from the environemnt and initiates the client.</p>
 */
@Inject
public ServiceRegistry() {

    try {
        String zookeeperUri = System.getenv("ZOOKEEPER_URI");

        zookeeper = CuratorFrameworkFactory.newClient(zookeeperUri, new RetryNTimes(5, 1000));

        zookeeper.start();

        zonePaths = new ConcurrentHashMap<>();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getLocalizedMessage());
    }
}
 
开发者ID:TFaga,项目名称:kumuluzee-examples,代码行数:19,代码来源:ServiceRegistry.java

示例10: createProperties

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
@Override
protected Properties createProperties() throws IOException {
	Properties prop = super.createProperties();
	if (zkLocation == null || "".equals(zkLocation))
		zkLocation = environment.getProperty(this.zkLocationEnvName);
	if (zkLocation == null) {
		logger.warn("ZK connection string env var does not exist, skip zk based configuration.");
		return prop;
	}
	try {
		RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
		CuratorFramework client = CuratorFrameworkFactory.newClient(zkLocation, retryPolicy);
		client.start();
		int count = CuratorUtils.loadToProperties(client, prop, "/");
		logger.info(String.format("Loaded %d properties from zookeeper.", count));
		client.close();
	} catch (Exception ex) {
		logger.warn("Failed to load configuration from ZK.", ex);
	}
	return prop;
}
 
开发者ID:NewTranx,项目名称:newtranx-utils,代码行数:22,代码来源:ZkPropertiesFactoryBean.java

示例11: CacheClusterService

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
private CacheClusterService(Config config) {
    try {
        if (config == null) {
            config = ConfigFactory.load();
        }

        this.zookeeperConnectionUrl = config.getString("zookeeper.connection_url");

        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        zkClient = CuratorFrameworkFactory.newClient(zookeeperConnectionUrl, retryPolicy);
        zkClient.start();

        clusterGlobalLock = new InterProcessReadWriteLock(zkClient, Constants.CACHE_CLUSTER_PATH);

        cacheClusterViewer = CacheClusterViewerFactory.getCacheClusterViewer();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:alain898,项目名称:distributed-search-cache,代码行数:20,代码来源:CacheClusterService.java

示例12: connect

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
/**
 * 获取curator对象
 * @return
 */
public CuratorFramework connect(){
    //声明一个重试策略
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.newClient(CuratorConfiguration.address, retryPolicy);
    client.start();
    return client;
}
 
开发者ID:mumudemo,项目名称:mumu-zookeeper,代码行数:12,代码来源:CuratorConnect.java

示例13: testSomeNodes

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的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

示例14: setUp

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    Configurator
        .initialize("FastMQ", Thread.currentThread().getContextClassLoader(), "log4j2.xml");
    CountDownLatch initLatch = new CountDownLatch(1);
    CuratorFramework curatorFramework = CuratorFrameworkFactory
        .newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
    curatorFramework.start();
    AsyncCuratorFramework asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
    when(offsetStorage.queryOffset(any())).thenReturn(new Offset());

    ledgerManager = new LogManagerImpl("ledger-manager-read-test-name", new BookKeeperConfig(),
        new BookKeeper("127.0.0.1:2181"), asyncCuratorFramework,
        new LogInfoStorageImpl(asyncCuratorFramework), this.offsetStorage);
    ledgerManager.init(new CommonCallback<Void, LedgerStorageException>() {
        @Override
        public void onCompleted(Void data, Version version) {
            initLatch.countDown();
        }

        @Override
        public void onThrowable(LedgerStorageException throwable) {
            throwable.printStackTrace();
            initLatch.countDown();
        }
    });
    initLatch.await();
}
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:29,代码来源:LogManagerImplTest.java

示例15: setUp

import org.apache.curator.framework.CuratorFrameworkFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
  zkServer = new TestingServer();
  client = CuratorFrameworkFactory
      .newClient("localhost:" + zkServer.getPort(),
          new ExponentialBackoffRetry(1000, 3));
  client.start();

  EnsurePath ensurePath = new EnsurePath(AGENT_PATH);
  ensurePath.ensure(client.getZookeeperClient());
  doSetUp();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:13,代码来源:TestAbstractZooKeeperConfigurationProvider.java


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