- 使用 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 {
我想了解 Ruby 方法 methods() 是如何工作的。 我尝试使用“ruby 方法”在 Google 上搜索,但这不是我需要的。 我也看过 ruby-doc.org,但我没有找到这种方法。
Test 方法 对指定的字符串执行一个正则表达式搜索,并返回一个 Boolean 值指示是否找到匹配的模式。 object.Test(string) 参数 object 必选项。总是一个
Replace 方法 替换在正则表达式查找中找到的文本。 object.Replace(string1, string2) 参数 object 必选项。总是一个 RegExp 对象的名称。
Raise 方法 生成运行时错误 object.Raise(number, source, description, helpfile, helpcontext) 参数 object 应为
Execute 方法 对指定的字符串执行正则表达式搜索。 object.Execute(string) 参数 object 必选项。总是一个 RegExp 对象的名称。 string
Clear 方法 清除 Err 对象的所有属性设置。 object.Clear object 应为 Err 对象的名称。 说明 在错误处理后,使用 Clear 显式地清除 Err 对象。此
CopyFile 方法 将一个或多个文件从某位置复制到另一位置。 object.CopyFile source, destination[, overwrite] 参数 object 必选
Copy 方法 将指定的文件或文件夹从某位置复制到另一位置。 object.Copy destination[, overwrite] 参数 object 必选项。应为 File 或 F
Close 方法 关闭打开的 TextStream 文件。 object.Close object 应为 TextStream 对象的名称。 说明 下面例子举例说明如何使用 Close 方
BuildPath 方法 向现有路径后添加名称。 object.BuildPath(path, name) 参数 object 必选项。应为 FileSystemObject 对象的名称
GetFolder 方法 返回与指定的路径中某文件夹相应的 Folder 对象。 object.GetFolder(folderspec) 参数 object 必选项。应为 FileSy
GetFileName 方法 返回指定路径(不是指定驱动器路径部分)的最后一个文件或文件夹。 object.GetFileName(pathspec) 参数 object 必选项。应为
GetFile 方法 返回与指定路径中某文件相应的 File 对象。 object.GetFile(filespec) 参数 object 必选项。应为 FileSystemObject
GetExtensionName 方法 返回字符串,该字符串包含路径最后一个组成部分的扩展名。 object.GetExtensionName(path) 参数 object 必选项。应
GetDriveName 方法 返回包含指定路径中驱动器名的字符串。 object.GetDriveName(path) 参数 object 必选项。应为 FileSystemObjec
GetDrive 方法 返回与指定的路径中驱动器相对应的 Drive 对象。 object.GetDrive drivespec 参数 object 必选项。应为 FileSystemO
GetBaseName 方法 返回字符串,其中包含文件的基本名 (不带扩展名), 或者提供的路径说明中的文件夹。 object.GetBaseName(path) 参数 object 必
GetAbsolutePathName 方法 从提供的指定路径中返回完整且含义明确的路径。 object.GetAbsolutePathName(pathspec) 参数 object
FolderExists 方法 如果指定的文件夹存在,则返回 True;否则返回 False。 object.FolderExists(folderspec) 参数 object 必选项
FileExists 方法 如果指定的文件存在返回 True;否则返回 False。 object.FileExists(filespec) 参数 object 必选项。应为 FileS
我是一名优秀的程序员,十分优秀!