gpt4 book ai didi

com.twitter.common.zookeeper.ZooKeeperClient类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 02:50:49 27 4
gpt4 key购买 nike

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

ZooKeeperClient介绍

[英]Manages a connection to a ZooKeeper cluster.
[中]管理与ZooKeeper群集的连接。

代码示例

代码示例来源:origin: pinterest/secor

public ZookeeperConnector(SecorConfig config) {
  mConfig = config;
  mZookeeperClient = new ZooKeeperClient(Amount.of(1, Time.DAYS), getZookeeperAddresses());
  mLocks = new HashMap<String, DistributedLock>();
}

代码示例来源:origin: pinterest/secor

private void createMissingParents(String path) throws Exception {
  ZooKeeper zookeeper = mZookeeperClient.get();
  assert path.charAt(0) == '/': path + ".charAt(0) == '/'";
  String[] elements = path.split("/");
  String prefix = "";
  for (int i = 1; i < elements.length - 1; ++i) {
    prefix += "/" + elements[i];
    try {
      zookeeper.create(prefix, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
      LOG.info("created path {}", prefix);
    } catch (KeeperException.NodeExistsException exception) {
    }
  }
}

代码示例来源:origin: twitter/distributedlog

public void close() {
    zkClient.close();
  }
}

代码示例来源:origin: com.twitter.common/zookeeper

@Override public Boolean get() throws JoinException {
  try {
   zkClient.get().delete(nodePath, ZooKeeperUtils.ANY_VERSION);
   return true;
  } catch (InterruptedException e) {
   Thread.currentThread().interrupt();
   throw new JoinException("Interrupted trying to cancel membership: " + nodePath, e);
  } catch (ZooKeeperConnectionException e) {
   LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
   return false;
  } catch (NoNodeException e) {
   LOG.info("Membership already cancelled, node at path: " + nodePath +
        " has been deleted");
   return true;
  } catch (KeeperException e) {
   if (zkClient.shouldRetry(e)) {
    LOG.log(Level.WARNING, "Temporary error cancelling membership: " + nodePath, e);
    return false;
   } else {
    throw new JoinException("Problem cancelling membership: " + nodePath, e);
   }
  }
 }
});

代码示例来源:origin: com.twitter.common/zookeeper

zkClient.registerExpirationHandler(new Command() {
  @Override public void execute() {
   tryJoin();
nodePath = zkClient.get().create(path + "/" + nodeNamePrefix, membershipData, acl,
  CreateMode.EPHEMERAL_SEQUENTIAL);
memberId = extractMemberId(nodePath);
zkClient.get().exists(nodePath, new Watcher() {
 @Override public void process(WatchedEvent event) {
  if (event.getType() == EventType.NodeDeleted) {

代码示例来源:origin: com.deciphernow/gm-fabric-core

public Command watch() throws WatchException, InterruptedException {
 Watcher onExpirationWatcher = zkClient.registerExpirationHandler(new Command() {
  @Override public void execute() {
   // Servers may have changed Status while we were disconnected from ZooKeeper, check and
   // re-register our node watches.
   rebuildServerSet();
  }
 });
 try {
  return group.watch(new GroupChangeListener() {
   @Override public void onGroupChange(Iterable<String> memberIds) {
    notifyGroupChange(memberIds);
   }
  });
 } catch (WatchException e) {
  zkClient.unregister(onExpirationWatcher);
  throw e;
 } catch (InterruptedException e) {
  zkClient.unregister(onExpirationWatcher);
  throw e;
 }
}

代码示例来源:origin: com.twitter.common.zookeeper/group

@Override public Boolean get() throws InterruptedException {
  try {
   watchGroup();
   return true;
  } catch (ZooKeeperConnectionException e) {
   LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
   return false;
  } catch (KeeperException e) {
   if (zkClient.shouldRetry(e)) {
    LOG.log(Level.WARNING, "Temporary error re-watching group: " + path, e);
    return false;
   } else {
    throw new IllegalStateException("Permanent problem re-watching group: " + path, e);
   }
  }
 }
};

代码示例来源:origin: com.twitter.common/zookeeper

public void watch() throws WatchException, InterruptedException {
 zkClient.registerExpirationHandler(new Command() {
  @Override public void execute() {
   // Servers may have changed Status while we were disconnected from ZooKeeper, check and
   // re-register our node watches.
   rebuildServerSet();
  }
 });
 group.watch(new GroupChangeListener() {
  @Override public void onGroupChange(Iterable<String> memberIds) {
   notifyGroupChange(memberIds);
  }
 });
}

代码示例来源:origin: com.twitter.common.zookeeper.guice/client

/**
 * Convenience method for calling {@link #withCredentials(Credentials)} with digest credentials.
 *
 * @param username Digest authentication user.
 * @param password Digest authentication raw password.
 * @return A modified clone of this configuration.
 */
public ClientConfig withDigestCredentials(String username, String password) {
 return withCredentials(ZooKeeperClient.digestCredentials(username, password));
}

代码示例来源:origin: com.twitter.common.zookeeper/group

@Override public Boolean get() throws JoinException {
  try {
   zkClient.get().delete(nodePath, ZooKeeperUtils.ANY_VERSION);
   return true;
  } catch (InterruptedException e) {
   Thread.currentThread().interrupt();
   throw new JoinException("Interrupted trying to cancel membership: " + nodePath, e);
  } catch (ZooKeeperConnectionException e) {
   LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
   return false;
  } catch (NoNodeException e) {
   LOG.info("Membership already cancelled, node at path: " + nodePath +
        " has been deleted");
   return true;
  } catch (KeeperException e) {
   if (zkClient.shouldRetry(e)) {
    LOG.log(Level.WARNING, "Temporary error cancelling membership: " + nodePath, e);
    return false;
   } else {
    throw new JoinException("Problem cancelling membership: " + nodePath, e);
   }
  }
 }
});

代码示例来源:origin: com.twitter.common.zookeeper/group

zkClient.registerExpirationHandler(new Command() {
  @Override public void execute() {
   tryJoin();
  ? CreateMode.EPHEMERAL_SEQUENTIAL
  : CreateMode.EPHEMERAL;
nodePath = zkClient.get().create(path + "/" + nodeName, membershipData, acl, createMode);
memberId = Group.this.getMemberId(nodePath);
LOG.info("Set group member ID to " + memberId);
zkClient.get().exists(nodePath, new Watcher() {
 @Override public void process(WatchedEvent event) {
  if (event.getType() == EventType.NodeDeleted) {

代码示例来源:origin: com.twitter.common/zookeeper

void init() throws InterruptedException, KeeperException,
  ZooKeeperConnectionException {
 Watcher watcher = zkClient.registerExpirationHandler(new Command() {
  @Override public void execute() {
   try {
  zkClient.unregister(watcher);
  throw e;
 } catch (KeeperException e) {
  zkClient.unregister(watcher);
  throw e;
 } catch (ZooKeeperConnectionException e) {
  zkClient.unregister(watcher);
  throw e;

代码示例来源:origin: com.twitter.common/zookeeper

@Override public Boolean get() throws InterruptedException {
  try {
   watchGroup();
   return true;
  } catch (ZooKeeperConnectionException e) {
   LOG.log(Level.WARNING, "Problem connecting to ZooKeeper, retrying", e);
   return false;
  } catch (KeeperException e) {
   if (zkClient.shouldRetry(e)) {
    LOG.log(Level.WARNING, "Temporary error re-watching group: " + path, e);
    return false;
   } else {
    throw new IllegalStateException("Permanent problem re-watching group: " + path, e);
   }
  }
 }
};

代码示例来源:origin: com.twitter.common/zookeeper

synchronized void setMembers(Iterable<String> members) {
  if (this.members == null) {
   // Reset our watch on the group if session expires - only needs to be registered once.
   zkClient.registerExpirationHandler(new Command() {
    @Override public void execute() {
     tryWatchGroup();
    }
   });
  }
  Set<String> membership = ImmutableSet.copyOf(members);
  if (!membership.equals(this.members)) {
   groupChangeListener.onGroupChange(members);
   this.members = membership;
  }
 }
}

代码示例来源:origin: com.twitter.common/zookeeper-testing

/**
 * Returns a new authenticated zookeeper client connected to the in-process zookeeper server with
 * the default session timeout.  The client is authenticated in the digest authentication scheme
 * with the given {@code username} and {@code password}.
 */
protected final ZooKeeperClient createZkClient(String username, String password) {
 return createZkClient(ZooKeeperClient.digestCredentials(username, password));
}

代码示例来源:origin: pinterest/secor

public long getCommittedOffsetCount(TopicPartition topicPartition) throws Exception {
  ZooKeeper zookeeper = mZookeeperClient.get();
  String offsetPath = getCommittedOffsetPartitionPath(topicPartition);
  try {
    byte[] data = zookeeper.getData(offsetPath, false, null);
    return Long.parseLong(new String(data));
  } catch (KeeperException.NoNodeException exception) {
    LOG.warn("path {} does not exist in zookeeper", offsetPath);
    return -1;
  }
}

代码示例来源:origin: com.twitter.common/zookeeper

@Override public ServiceInstance get() {
  try {
   byte[] data = zkClient.get().getData(nodePath, serviceInstanceWatcher, null);
   return codec.deserialize(new ByteArrayInputStream(data));
  } catch (InterruptedException e) {
   Thread.currentThread().interrupt();
   throw new ServiceInstanceFetchException(
     "Interrupted updating service data for: " + nodePath, e);
  } catch (ZooKeeperConnectionException e) {
   LOG.log(Level.WARNING,
     "Temporary error trying to updating service data for: " + nodePath, e);
   return null;
  } catch (NoNodeException e) {
   invalidateNodePath(nodePath);
   throw new ServiceInstanceDeletedException(nodePath);
  } catch (KeeperException e) {
   if (zkClient.shouldRetry(e)) {
    LOG.log(Level.WARNING,
      "Temporary error trying to update service data for: " + nodePath, e);
    return null;
   } else {
    throw new ServiceInstanceFetchException(
      "Failed to update service data for: " + nodePath, e);
   }
  } catch (IOException e) {
   throw new ServiceInstanceFetchException(
     "Failed to deserialize the ServiceInstance data for: " + nodePath, e);
  }
 }
});

代码示例来源:origin: twitter/distributedlog

public static DLZkServerSet of(URI uri,
                int zkSessionTimeoutMs) {
  // Create zookeeper and server set
  String zkPath = uri.getPath() + "/" + ZNODE_WRITE_PROXY;
  Iterable<InetSocketAddress> zkAddresses = getZkAddresses(uri);
  ZooKeeperClient zkClient =
      new ZooKeeperClient(Amount.of(zkSessionTimeoutMs, Time.MILLISECONDS), zkAddresses);
  ServerSet serverSet = ServerSets.create(zkClient, ZooDefs.Ids.OPEN_ACL_UNSAFE, zkPath);
  return new DLZkServerSet(zkClient, serverSet);
}

代码示例来源:origin: com.senseidb.zu/zu-core

/**
 * shuts down the cluster and closes connection to zookeeper
 */
public void shutdown() {
 if (zkClient != null) {
  zkClient.close();
 }
}

代码示例来源:origin: com.twitter.common/zookeeper

void init() throws InterruptedException, KeeperException,
  ZooKeeperConnectionException {
 Watcher watcher = zkClient.registerExpirationHandler(new Command() {
  @Override public void execute() {
  zkClient.unregister(watcher);
  throw e;
 } catch (KeeperException e) {
  zkClient.unregister(watcher);
  throw e;
 } catch (ZooKeeperConnectionException e) {
  zkClient.unregister(watcher);
  throw e;

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com