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


Java CuratorFrameworkFactory類代碼示例

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


CuratorFrameworkFactory類屬於org.apache.curator.framework包,在下文中一共展示了CuratorFrameworkFactory類的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: init

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
@PostConstruct
public void init() {
  log.info("Initializing...");
  Assert.hasLength(zkUrl, MiscUtils.missingProperty("zk.url"));
  Assert.notNull(zkRetryInterval, MiscUtils.missingProperty("zk.retry_interval_ms"));
  Assert.notNull(zkConnectionTimeout, MiscUtils.missingProperty("zk.connection_timeout_ms"));
  Assert.notNull(zkSessionTimeout, MiscUtils.missingProperty("zk.session_timeout_ms"));

  log.info("Initializing discovery service using ZK connect string: {}", zkUrl);

  zkNodesDir = zkDir + "/nodes";
  try {
    client = CuratorFrameworkFactory.newClient(zkUrl, zkSessionTimeout, zkConnectionTimeout,
        new RetryForever(zkRetryInterval));
    client.start();
    client.blockUntilConnected();
    cache = new PathChildrenCache(client, zkNodesDir, true);
    cache.getListenable().addListener(this);
    cache.start();
  } catch (Exception e) {
    log.error("Failed to connect to ZK: {}", e.getMessage(), e);
    CloseableUtils.closeQuietly(client);
    throw new RuntimeException(e);
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:26,代碼來源:ZkDiscoveryService.java

示例3: get

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

    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

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

    try {
        //Ensure the chrooted path for stroom-services exists
        Stat stat = client.checkExists().forPath("/");
        if (stat == null) {
            LOGGER.info("Creating chroot-ed root node inside " + serviceDiscoveryPath);
            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,代碼來源:ServiceDiscoveryCuratorFrameworkProvider.java

示例4: buildConnection

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的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

示例5: testServer

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
public void testServer(){
        try {
        TestingServer server=new TestingServer(2181,new File("/"));
        server.start();

        CuratorFramework curatorFramework = CuratorFrameworkFactory.
                builder().
                connectString(server.getConnectString()).
                sessionTimeoutMs(1000).
                retryPolicy(new RetryNTimes(3, 1000)).
                build();
        curatorFramework.start();
        System.out.println(curatorFramework.getChildren().forPath("/"));
        curatorFramework.close();
        server.stop();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
開發者ID:mumudemo,項目名稱:mumu-zookeeper,代碼行數:21,代碼來源:CuratorServer.java

示例6: SingularityCuratorProvider

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
@Inject
public SingularityCuratorProvider(final SingularityConfiguration configuration, final Set<ConnectionStateListener> connectionStateListeners) {

  checkNotNull(configuration, "configuration is null");
  checkNotNull(connectionStateListeners, "connectionStateListeners is null");

  ZooKeeperConfiguration zookeeperConfig = configuration.getZooKeeperConfiguration();

  this.curatorFramework = CuratorFrameworkFactory.builder()
      .defaultData(null)
      .sessionTimeoutMs(zookeeperConfig.getSessionTimeoutMillis())
      .connectionTimeoutMs(zookeeperConfig.getConnectTimeoutMillis())
      .connectString(zookeeperConfig.getQuorum())
      .retryPolicy(new ExponentialBackoffRetry(zookeeperConfig.getRetryBaseSleepTimeMilliseconds(), zookeeperConfig.getRetryMaxTries()))
      .namespace(zookeeperConfig.getZkNamespace()).build();

  for (ConnectionStateListener connectionStateListener : connectionStateListeners) {
    curatorFramework.getConnectionStateListenable().addListener(connectionStateListener);
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:21,代碼來源:SingularityCuratorProvider.java

示例7: run

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
@Override
public void run(String... strings) throws Exception {
    client = CuratorFrameworkFactory.newClient(zookeeperConnString,
            new ExponentialBackoffRetry(1000, Integer.MAX_VALUE));
    client.start();
    client.getZookeeperClient().blockUntilConnectedOrTimedOut();

    leaderLatch = new LeaderLatch(client, "/http-job-scheduler/leader",
            ManagementFactory.getRuntimeMXBean().getName());

    leaderLatch.addListener(new LeaderLatchListener() {
        @Override
        public void isLeader() {
            setMaster(true);
            masterJobScheduler.resume();
        }

        @Override
        public void notLeader() {
            setMaster(false);
            masterJobScheduler.pause();
        }
    });
    leaderLatch.start();
}
 
開發者ID:flipkart-incubator,項目名稱:simpleJobScheduler,代碼行數:26,代碼來源:Application.java

示例8: setUp

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的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

示例9: CuratorUtils

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
public CuratorUtils(String connectString, Host host) {
    this.host = host;

    client = CuratorFrameworkFactory.builder()
            .connectString(connectString)
            .sessionTimeoutMs(10000)
            .connectionTimeoutMs(10000)
            .retryPolicy(new ExponentialBackoffRetry(1000, 3))
            .build();
    client.start();
    try {
        path = generatePath();
        if (null == path) {
            log.error("init curator failed due to path is null!");
            throw new DriverException("init curator failed due to path is null, servie will down");
        }
    } catch (Exception e) {
        log.error("CuratorUtils construct failed, service will down!");
        client.close();
        System.exit(-1);
    }
}
 
開發者ID:HujiangTechnology,項目名稱:Juice,代碼行數:23,代碼來源:CuratorUtils.java

示例10: curatorFramework

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
@Bean(initMethod = "start", destroyMethod = "close")
@Lazy(false)
public CuratorFramework curatorFramework() {
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory
            .builder();
    int sessionTimeoutMs = Integer.parseInt(env.getProperty(
            "rpc.client.zookeeper.session.timeout.ms", "5000"));
    int connectionTimeoutMs = Integer.parseInt(env.getProperty(
            "rpc.client.zookeeper.connection.timeout.ms", "5000"));
    builder.connectString(
            env.getProperty("rpc.client.zookeeper.connect.string"))
            .sessionTimeoutMs(sessionTimeoutMs)
            .connectionTimeoutMs(connectionTimeoutMs)
           
            .retryPolicy(this.retryPolicy());
            //.aclProvider(this.aclProvider()).authorization(this.authInfo());
    return builder.build();
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:19,代碼來源:HelloClientConfig.java

示例11: curatorFramework

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
@Bean(name = "curator-framework")
public CuratorFramework curatorFramework() {
	return CuratorFrameworkFactory
			.builder()
			.connectString(
					env.getProperty("rpc.server.zookeeper.connect.string"))
			.sessionTimeoutMs(
					Integer.parseInt(env.getProperty(
							"rpc.server.zookeeper.session.timeout.ms",
							"10000")))
			.connectionTimeoutMs(
					Integer.parseInt(env.getProperty(
							"rpc.server.zookeeper.connection.timeout.ms",
							"10000"))).retryPolicy(this.retryPolicy())
			.aclProvider(this.aclProvider()).authorization(this.authInfo())
			.build();
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:18,代碼來源:HelloServerConfig.java

示例12: curatorFramework

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
@Bean(initMethod = "start", destroyMethod = "close")
public CuratorFramework curatorFramework() {
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory
            .builder();
    int sessionTimeoutMs = Integer.parseInt(env.getProperty(
            "rpc.client.zookeeper.session.timeout.ms", "5000"));
    int connectionTimeoutMs = Integer.parseInt(env.getProperty(
            "rpc.client.zookeeper.connection.timeout.ms", "5000"));
    builder.connectString(
            env.getProperty("rpc.client.zookeeper.connect.string"))
            .sessionTimeoutMs(sessionTimeoutMs)
            .connectionTimeoutMs(connectionTimeoutMs)	               
            .retryPolicy(this.retryPolicy())
            .aclProvider(this.aclProvider()).authorization(this.authInfo());
    return builder.build();
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:17,代碼來源:HelloClientConfig.java

示例13: ZkService

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的package包/類
/**
 * 創建ZK連接
 * @param connectString  ZK服務器地址列表
 * @param sessionTimeout   Session超時時間
 */
public ZkService(String connectString, int sessionTimeout) throws Exception {
    CuratorFrameworkFactory.Builder builder;
    builder = CuratorFrameworkFactory.builder()
            .connectString(connectString)
            .namespace("")
            .authorization("digest", auth.getBytes())
            .retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000))
            .connectionTimeoutMs(sessionTimeout);

    client = builder.build();
    client.start();
    if(!client.blockUntilConnected(20, TimeUnit.SECONDS)) {
        throw new Exception("zookeeper connected failed!");
    }

    tableVersions = new HashMap<>();
    cache = new HashMap<>();
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:24,代碼來源:ZkService.java

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

示例15: createConnection

import org.apache.curator.framework.CuratorFrameworkFactory; //導入依賴的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


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