org.lilyproject.util.zookeeper.ZkUtil类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中org.lilyproject.util.zookeeper.ZkUtil类的一些代码示例,展示了ZkUtil类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkUtil类的具体详情如下:
包路径:org.lilyproject.util.zookeeper.ZkUtil
类名称:ZkUtil

ZkUtil介绍

[英]Various ZooKeeper utility methods.
[中]

代码示例

代码示例来源:origin: NGDATA/lilyproject

  1. public static void createPath(final ZooKeeperItf zk, final String path)
  2. throws InterruptedException, KeeperException {
  3. createPath(zk, path, null);
  4. }

代码示例来源:origin: NGDATA/lilyproject

  1. public LilyClient(String zookeeperConnectString, int sessionTimeout, boolean keepAlive) throws IOException, InterruptedException,
  2. KeeperException, ZkConnectException, NoServersException, RepositoryException {
  3. this(ZkUtil.connect(zookeeperConnectString, sessionTimeout), keepAlive);
  4. managedZk = true;
  5. }

代码示例来源:origin: NGDATA/lilyproject

  1. private Server createServer() throws Exception {
  2. if (this.useSolrCloud) {
  3. // create path on zookeeper for solr cloud
  4. ZooKeeperItf zk = ZkUtil.connect("localhost:2181", 10000);
  5. ZkUtil.createPath(zk, "/solr");
  6. zk.close();
  7. }
  8. Server server = new Server(solrPort);
  9. WebAppContext ctx = new WebAppContext(solrWarPath, "/solr");
  10. // The reason to change the classloading behavior was primarily so that the logging libraries would
  11. // be inherited, and hence that Solr would use the same logging system & conf.
  12. ctx.setParentLoaderPriority(true);
  13. server.addHandler(ctx);
  14. return server;
  15. }

代码示例来源:origin: NGDATA/lilyproject

  1. @Override
  2. public Void call() throws Exception {
  3. String bucketId = watcher.getBucket();
  4. String bucketPath = bucketPath(bucketId);
  5. Stat stat = new Stat();
  6. try {
  7. ZkUtil.getData(zooKeeper, bucketPath, watcher, stat);
  8. bucketVersions.put(bucketId, stat.getVersion());
  9. } catch (KeeperException e) {
  10. if (Thread.currentThread().isInterrupted()) {
  11. if (log.isDebugEnabled()) {
  12. log.debug(
  13. "Failed to put watcher on bucket " + bucketPath + " : thread interrupted");
  14. }
  15. } else {
  16. log.warn("Failed to put watcher on bucket " + bucketPath
  17. + " - Relying on connection watcher to reinitialize cache", e);
  18. // Failed to put our watcher.
  19. // Relying on the ConnectionWatcher to put it again and
  20. // initialize the caches.
  21. }
  22. }
  23. return null;
  24. }
  25. });

代码示例来源:origin: NGDATA/lilyproject

  1. /**
  2. * Sets the cache refresh flag on Zookeeper. This triggers the caches to
  3. * refresh their data.
  4. *
  5. * @param force
  6. * if true, it is ignored if cache refreshing is enabled or not.
  7. */
  8. public void triggerRefresh(byte[] rowKey, boolean force) throws TypeException, InterruptedException {
  9. if (force || cacheRefreshingEnabled) {
  10. try {
  11. if (rowKey == null) {
  12. if (log.isDebugEnabled()) {
  13. log.debug("Triggering schema cache refresh for all types.");
  14. }
  15. ZkUtil.update(zooKeeper, CACHE_INVALIDATION_PATH, null, -1);
  16. } else {
  17. String bucketId = encodeHex(rowKey);
  18. if (log.isDebugEnabled()) {
  19. log.debug("Triggering schema cache refresh for bucket: " + bucketId);
  20. }
  21. ZkUtil.update(zooKeeper, CACHE_INVALIDATION_PATH + "/" + bucketId, null, -1);
  22. }
  23. } catch (KeeperException e) {
  24. throw new TypeException("Exception while triggering cache refresh", e);
  25. }
  26. }
  27. }

代码示例来源:origin: NGDATA/lilyproject

  1. Stat stat = new Stat();
  2. try {
  3. ZkUtil.getData(zooKeeper, bucketPath, watcher, stat);
  4. if (stat.getVersion() == bucketVersions.get(bucketId)) {
  5. continue; // The bucket is up to date

代码示例来源:origin: NGDATA/lilyproject

  1. @Override
  2. public Void call() throws InterruptedException, KeeperException, RepositoryException {
  3. for (int j = 0; j < 16; j++) {
  4. String bucket = "" + DIGITS_LOWER[index] + DIGITS_LOWER[j];
  5. ZkUtil.createPath(zooKeeper, bucketPath(bucket));
  6. cacheWatchers.add(new CacheWatcher(bucket));
  7. }
  8. return null;
  9. }
  10. }));

代码示例来源:origin: NGDATA/lilyproject

  1. @Override
  2. public void run() {
  3. try {
  4. ZooKeeperItf zk = ZkUtil.connect("localhost:2181,localhost:21812", 5000);
  5. new LeaderElection(zk, "electiontest", "/lily/electiontest/leaders", new Callback());
  6. } catch (Exception e) {
  7. e.printStackTrace();
  8. }
  9. }

代码示例来源:origin: NGDATA/lilyproject

  1. ZkUtil.getData(zooKeeper, CACHE_INVALIDATION_PATH, parentWatcher, stat);
  2. if (parentVersion == null || (stat.getVersion() != parentVersion)) {
  3. Stat stat = new Stat();
  4. try {
  5. ZkUtil.getData(zooKeeper, bucketPath, watcher, stat);
  6. Integer oldVersion = bucketVersions.get(bucketId);
  7. if (oldVersion == null || (oldVersion != stat.getVersion())) {

代码示例来源:origin: NGDATA/lilyproject

  1. @PostConstruct
  2. public void init() throws KeeperException, InterruptedException {
  3. ZkUtil.createPath(zk, "/lily/repositoryNodes");
  4. refresh();
  5. }

代码示例来源:origin: NGDATA/lilyproject

  1. /**
  2. * Factory method for creation of a {@code BulkIngester} that operates on a non-default repository table.
  3. *
  4. * @param zkConnString connection string for ZooKeeper
  5. * @param timeout ZooKeeper session timeout
  6. * @param tableName name of the repository table to write to
  7. */
  8. public static BulkIngester newBulkIngester(String zkConnString, int timeout, String repositoryName, String tableName,
  9. boolean bulkMode) {
  10. try {
  11. ZooKeeperItf zk = ZkUtil.connect(zkConnString, timeout);
  12. // we need a lily client for non bulk access
  13. LilyClient lilyClient = new LilyClient(zk);
  14. // we need an HBaseRepository for bulk access
  15. Configuration conf = HBaseConfiguration.create();
  16. conf.set("hbase.zookeeper.quorum", zkConnString);
  17. HBaseTableFactory hbaseTableFactory = new HBaseTableFactoryImpl(conf);
  18. HBaseRepository hbaseRepository = createHBaseRepository(repositoryName, tableName, zk, conf, hbaseTableFactory);
  19. return new BulkIngester(
  20. lilyClient,
  21. hbaseRepository,
  22. LilyHBaseSchema.getRecordTable(hbaseTableFactory, hbaseRepository.getRepositoryName(),
  23. hbaseRepository.getTableName()),
  24. bulkMode);
  25. } catch (Exception e) {
  26. ExceptionUtil.handleInterrupt(e);
  27. throw new RuntimeException(e);
  28. }
  29. }

代码示例来源:origin: NGDATA/lilyproject

  1. @PostConstruct
  2. public void start() throws IOException, InterruptedException, KeeperException {
  3. // Publish our address
  4. ZkUtil.createPath(zk, nodesPath);
  5. final String repoAddressAndPort = hostAddress + ":" + port;
  6. zk.retryOperation(new ZooKeeperOperation<Object>() {
  7. @Override
  8. public Object execute() throws KeeperException, InterruptedException {
  9. zk.create(nodesPath + "/" + repoAddressAndPort, null, ZooDefs.Ids.OPEN_ACL_UNSAFE,
  10. CreateMode.EPHEMERAL);
  11. return null;
  12. }
  13. });
  14. // Publish HBase configuration for LilyClient use
  15. // Translate HBase conf into json
  16. ObjectNode propertiesNode = JsonNodeFactory.instance.objectNode();
  17. for (Map.Entry<String, String> propertyEntry : hbaseConf) {
  18. if (!propertyEntry.getKey().equals(HConstants.HBASE_CLIENT_INSTANCE_ID)) {
  19. propertiesNode.put(propertyEntry.getKey(), propertyEntry.getValue());
  20. }
  21. }
  22. // TODO we could compare with current state and log a warn if its different
  23. ZkUtil.createPath(zk, hbaseConfPath, JsonFormat.serializeAsBytes(propertiesNode));
  24. }
  25. }

代码示例来源:origin: NGDATA/lilyproject

  1. public void setupCore() throws Exception {
  2. if (coreSetup) {
  3. return;
  4. }
  5. hbaseProxy = new HBaseProxy();
  6. hbaseProxy.start();
  7. hadoopConf = hbaseProxy.getConf();
  8. zk = ZkUtil.connect(hbaseProxy.getZkConnectString(), 10000);
  9. hbaseTableFactory = new HBaseTableFactoryImpl(hadoopConf);
  10. repositoryModel = new RepositoryModelImpl(zk);
  11. repositoryMaster = new RepositoryMaster(zk, repositoryModel, new DummyLilyInfo(),
  12. Collections.<RepositoryMasterHook>singletonList(new CoreRepositoryMasterHook(hbaseTableFactory, hbaseProxy.getConf())));
  13. repositoryMaster.start();
  14. coreSetup = true;
  15. }

代码示例来源:origin: NGDATA/lilyproject

  1. public void start() throws InterruptedException, KeeperException, RepositoryException {
  2. cacheRefresher.start();
  3. ZkUtil.createPath(zooKeeper, CACHE_INVALIDATION_PATH);
  4. final ExecutorService threadPool = Executors.newFixedThreadPool(50);
  5. final List<Future> futures = new ArrayList<Future>();
  6. ZkUtil.createPath(zooKeeper, CACHE_REFRESHENABLED_PATH);
  7. connectionWatcher = new ConnectionWatcher();
  8. zooKeeper.addDefaultWatcher(connectionWatcher);

代码示例来源:origin: NGDATA/lilyproject

  1. private void proposeAsLeader() throws LeaderElectionSetupException, InterruptedException, KeeperException {
  2. ZkUtil.createPath(zk, electionPath);
  3. try {
  4. // In case of connection loss, a node might have been created for us (we do not know it). Therefore,
  5. // retrying upon connection loss is important, so that we can continue with watching the leaders.
  6. // Later on, we do not look at the name of the node we created here, but at the owner.
  7. zk.retryOperation(new ZooKeeperOperation<String>() {
  8. @Override
  9. public String execute() throws KeeperException, InterruptedException {
  10. return zk.create(electionPath + "/n_", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
  11. }
  12. });
  13. } catch (KeeperException e) {
  14. throw new LeaderElectionSetupException("Error creating leader election zookeeper node below " +
  15. electionPath, e);
  16. }
  17. watchLeaders();
  18. }

代码示例来源:origin: NGDATA/lilyproject

  1. public void init() throws KeeperException, InterruptedException {
  2. ZkUtil.createPath(zk, REPOSITORY_COLLECTION_PATH);
  3. assureDefaultRepositoryExists();
  4. zkWatcher = new RepositoryZkWatcher();
  5. zk.addDefaultWatcher(zkWatcher);
  6. refresh();
  7. }

相关文章