- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.retryOperation()
方法的一些代码示例,展示了ZooKeeperItf.retryOperation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperItf.retryOperation()
方法的具体详情如下:
包路径:org.lilyproject.util.zookeeper.ZooKeeperItf
类名称:ZooKeeperItf
方法名:retryOperation
[英]Perform the given operation, retrying in case of connection loss.
Note that in case of connection loss, you are never sure if the operation succeeded or not, so it might be executed twice. Therefore:
Do not call this method from within a ZooKeeper watcher callback, as it might block for a longer time and hence block the delivery of other events, including the Disconnected event.
This is a Lily-specific method.
[中]执行给定的操作,在连接丢失时重试。
请注意,在连接丢失的情况下,您永远无法确定操作是否成功,因此可能会执行两次。因此:
*如果是删除操作,请准备好处理非节点异常
*如果是创建操作,请准备好处理NodeExists异常
*在创建顺序节点的情况下,可能已经创建了两个节点。如果它们是短暂的,可以使用Stat.ephemeralOwner查找属于当前会话的。否则,在名称或数据中嵌入必要的标识。
不要在ZooKeeper watcher回调中调用此方法,因为它可能会阻塞更长的时间,从而阻塞其他事件的传递,包括断开连接的事件。
这是一种百合特有的方法。
代码示例来源:origin: NGDATA/lilyproject
/**
* Updates data on a zookeeper node.
*
* <p>
* The supplied data is used for the last node in the path. The path must
* already exist. It is not checked if the data is changed or not. This will
* cause the version of the node to be increased.
* <p>
* This operation is retried until it succeeds.
*/
public static void update(final ZooKeeperItf zk, final String path, final byte[] data, final int version)
throws InterruptedException, KeeperException {
zk.retryOperation(new ZooKeeperOperation<Boolean>() {
@Override
public Boolean execute() throws KeeperException, InterruptedException {
zk.setData(path, data, version);
return null;
}
});
}
代码示例来源:origin: NGDATA/lilyproject
/**
* Deletes a path (non-recursively) in ZooKeeper, if it exists.
* <p>
* If the path doesn't exist, the delete will fail silently. The delete operation is retried until it succeeds, or
* until it fails with a non-recoverable error.
* <p>
* If the path has children, the operation will fail with the underlying {@link NotEmptyException}.
*
* @param zk Handle to the ZooKeeper where the delete will occur
* @param path The path to be deleted
*/
public static void deleteNode(final ZooKeeperItf zk, final String path) throws InterruptedException,
KeeperException {
zk.retryOperation(new ZooKeeperOperation<Boolean>() {
@Override
public Boolean execute() throws KeeperException, InterruptedException {
Stat stat = zk.exists(path, false);
if (stat != null) {
try {
zk.delete(path, stat.getVersion());
} catch (KeeperException.NoNodeException nne) {
// This is ok, the node is already gone
}
// We don't catch BadVersion or NotEmpty as these are probably signs that there is something
// unexpected going on with the node that is to be deleted
}
return true;
}
});
}
代码示例来源:origin: NGDATA/lilyproject
/**
* Gets data from a zookeeper node.
* <p>
* This operation is retried until it succeeds.
*/
public static byte[] getData(final ZooKeeperItf zk, final String path, final Watcher watcher, final Stat stat)
throws InterruptedException, KeeperException {
final List<byte[]> data = new ArrayList<byte[]>(1);
zk.retryOperation(new ZooKeeperOperation<Boolean>() {
@Override
public Boolean execute() throws KeeperException, InterruptedException {
data.add(zk.getData(path, watcher, stat));
return null;
}
});
return data.get(0);
}
}
代码示例来源:origin: NGDATA/lilyproject
@Override
public <T> T retryOperation(com.ngdata.sep.util.zookeeper.ZooKeeperOperation<T> operation) throws InterruptedException, KeeperException {
return wrapped.retryOperation(new ZooKeeperOperationAdapter<T>(operation));
}
代码示例来源:origin: NGDATA/lilyproject
created = zk.retryOperation(new ZooKeeperOperation<Boolean>() {
@Override
public Boolean execute() throws KeeperException, InterruptedException {
zk.retryOperation(new ZooKeeperOperation<Boolean>() {
@Override
public Boolean execute() throws KeeperException, InterruptedException {
代码示例来源:origin: NGDATA/lilyproject
/**
* Verifies that the specified lockId is the owner of the lock.
*/
public static boolean ownsLock(final ZooKeeperItf zk, final String lockId) throws ZkLockException {
if (zk.isCurrentThreadEventThread()) {
throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread.");
}
try {
int lastSlashPos = lockId.lastIndexOf('/');
final String lockPath = lockId.substring(0, lastSlashPos);
String lockName = lockId.substring(lastSlashPos + 1);
List<String> children = zk.retryOperation(new ZooKeeperOperation<List<String>>() {
@Override
public List<String> execute() throws KeeperException, InterruptedException {
return zk.getChildren(lockPath, null);
}
});
if (children.isEmpty()) {
return false;
}
SortedSet<String> sortedChildren = new TreeSet<String>(children);
return sortedChildren.first().equals(lockName);
} catch (Throwable t) {
throw new ZkLockException("Error checking lock, path: " + lockId, t);
}
}
代码示例来源:origin: NGDATA/lilyproject
@PostConstruct
public void start() throws IOException, InterruptedException, KeeperException {
// Publish our address
ZkUtil.createPath(zk, nodesPath);
final String repoAddressAndPort = hostAddress + ":" + port;
zk.retryOperation(new ZooKeeperOperation<Object>() {
@Override
public Object execute() throws KeeperException, InterruptedException {
zk.create(nodesPath + "/" + repoAddressAndPort, null, ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.EPHEMERAL);
return null;
}
});
// Publish HBase configuration for LilyClient use
// Translate HBase conf into json
ObjectNode propertiesNode = JsonNodeFactory.instance.objectNode();
for (Map.Entry<String, String> propertyEntry : hbaseConf) {
if (!propertyEntry.getKey().equals(HConstants.HBASE_CLIENT_INSTANCE_ID)) {
propertiesNode.put(propertyEntry.getKey(), propertyEntry.getValue());
}
}
// TODO we could compare with current state and log a warn if its different
ZkUtil.createPath(zk, hbaseConfPath, JsonFormat.serializeAsBytes(propertiesNode));
}
}
代码示例来源:origin: NGDATA/lilyproject
@Override
public int run(CommandLine cmd) throws Exception {
int result = super.run(cmd);
if (result != 0) {
return result;
}
zk = new StateWatchingZooKeeper(zkConnectionString, zkSessionTimeout);
boolean lilyNodeExists = zk.retryOperation(new ZooKeeperOperation<Boolean>() {
@Override
public Boolean execute() throws KeeperException, InterruptedException {
return zk.exists("/lily", false) != null;
}
});
if (!lilyNodeExists) {
if (!cmd.hasOption(forceOption.getOpt())) {
System.out.println("No /lily node found in ZooKeeper. Are you sure you are connecting to the right");
System.out.println("ZooKeeper? If so, use the option --" + forceOption.getLongOpt() +
" to bypass this check.");
return 1;
} else {
System.out.println("No /lily node found in ZooKeeper. Will continue anyway since you supplied --" +
forceOption.getLongOpt());
System.out.println();
}
}
repositoryModel = new RepositoryModelImpl(zk);
return 0;
}
代码示例来源:origin: NGDATA/lilyproject
private void proposeAsLeader() throws LeaderElectionSetupException, InterruptedException, KeeperException {
ZkUtil.createPath(zk, electionPath);
try {
// In case of connection loss, a node might have been created for us (we do not know it). Therefore,
// retrying upon connection loss is important, so that we can continue with watching the leaders.
// Later on, we do not look at the name of the node we created here, but at the owner.
zk.retryOperation(new ZooKeeperOperation<String>() {
@Override
public String execute() throws KeeperException, InterruptedException {
return zk.create(electionPath + "/n_", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
}
});
} catch (KeeperException e) {
throw new LeaderElectionSetupException("Error creating leader election zookeeper node below " +
electionPath, e);
}
watchLeaders();
}
代码示例来源:origin: NGDATA/lilyproject
/**
* Releases a lock.
*
* @param lockId the string returned by {@link ZkLock#lock}.
* @param ignoreMissing if true, do not throw an exception if the lock does not exist
*/
public static void unlock(final ZooKeeperItf zk, final String lockId, boolean ignoreMissing) throws ZkLockException {
if (zk.isCurrentThreadEventThread()) {
throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread.");
}
try {
zk.retryOperation(new ZooKeeperOperation<Object>() {
@Override
public Object execute() throws KeeperException, InterruptedException {
zk.delete(lockId, -1);
return null;
}
});
} catch (KeeperException.NoNodeException e) {
if (!ignoreMissing) {
throw new ZkLockException("Error releasing lock: the lock does not exist. Path: " + lockId, e);
}
} catch (Throwable t) {
throw new ZkLockException("Error releasing lock, path: " + lockId, t);
}
}
代码示例来源:origin: NGDATA/lilyproject
zk.retryOperation(new ZooKeeperOperation<String>() {
@Override
public String execute() throws KeeperException, InterruptedException {
List<ZkLockNode> children = parseChildren(zk.retryOperation(new ZooKeeperOperation<List<String>>() {
@Override
public List<String> execute() throws KeeperException, InterruptedException {
Stat stat = zk.retryOperation(new ZooKeeperOperation<Stat>() {
@Override
public Stat execute() throws KeeperException, InterruptedException {
zk.retryOperation(new ZooKeeperOperation<Object>() {
@Override
public Object execute() throws KeeperException, InterruptedException {
final MyWatcher watcher = new MyWatcher(pathToWatch, condition);
Stat stat = zk.retryOperation(new ZooKeeperOperation<Stat>() {
@Override
public Stat execute() throws KeeperException, InterruptedException {
本文整理了Java中org.lilyproject.sep.ZooKeeperItfAdapter类的一些代码示例,展示了ZooKeeperItfAdapter类的具体用法。这些代码示例主要来源于Gi
本文整理了Java中org.lilyproject.util.zookeeper.ZkUtil类的一些代码示例,展示了ZkUtil类的具体用法。这些代码示例主要来源于Github/Stackoverf
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf类的一些代码示例,展示了ZooKeeperItf类的具体用法。这些代码示例主要来源于Githu
本文整理了Java中org.lilyproject.sep.ZooKeeperItfAdapter.()方法的一些代码示例,展示了ZooKeeperItfAdapter.()的具体用法。这些代码示例主
本文整理了Java中org.lilyproject.util.zookeeper.ZkUtil.connect()方法的一些代码示例,展示了ZkUtil.connect()的具体用法。这些代码示例主要
本文整理了Java中org.lilyproject.util.zookeeper.ZkUtil.createPath()方法的一些代码示例,展示了ZkUtil.createPath()的具体用法。这些
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.delete()方法的一些代码示例,展示了ZooKeeperItf.delete()的具体用
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.getSessionPasswd()方法的一些代码示例,展示了ZooKeeperItf.ge
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.close()方法的一些代码示例,展示了ZooKeeperItf.close()的具体用法。
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.getSessionId()方法的一些代码示例,展示了ZooKeeperItf.getSes
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.isCurrentThreadEventThread()方法的一些代码示例,展示了ZooKe
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.addDefaultWatcher()方法的一些代码示例,展示了ZooKeeperItf.a
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.setData()方法的一些代码示例,展示了ZooKeeperItf.setData()的具
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.removeDefaultWatcher()方法的一些代码示例,展示了ZooKeeperIt
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.create()方法的一些代码示例,展示了ZooKeeperItf.create()的具体用
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.exists()方法的一些代码示例,展示了ZooKeeperItf.exists()的具体用
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.getChildren()方法的一些代码示例,展示了ZooKeeperItf.getChil
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.getData()方法的一些代码示例,展示了ZooKeeperItf.getData()的具
本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf.retryOperation()方法的一些代码示例,展示了ZooKeeperItf.retr
我是一名优秀的程序员,十分优秀!