本文整理汇总了Java中org.I0Itec.zkclient.DataUpdater.update方法的典型用法代码示例。如果您正苦于以下问题:Java DataUpdater.update方法的具体用法?Java DataUpdater.update怎么用?Java DataUpdater.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.I0Itec.zkclient.DataUpdater
的用法示例。
在下文中一共展示了DataUpdater.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateDataSerialized
import org.I0Itec.zkclient.DataUpdater; //导入方法依赖的package包/类
/**
* Updates data of an existing znode. The current content of the znode is passed to the {@link DataUpdater} that is
* passed into this method, which returns the new content. The new content is only written back to ZooKeeper if
* nobody has modified the given znode in between. If a concurrent change has been detected the new data of the
* znode is passed to the updater once again until the new contents can be successfully written back to ZooKeeper.
*
* @param <T>
* @param path
* The path of the znode.
* @param updater
* Updater that creates the new contents.
*/
@SuppressWarnings("unchecked") public <T extends Object> void updateDataSerialized(String path,
DataUpdater<T> updater) {
Stat stat = new Stat();
boolean retry;
do {
retry = false;
try {
T oldData = (T) readData(path, stat);
T newData = updater.update(oldData);
writeData(path, newData, stat.getVersion());
} catch (ZkBadVersionException e) {
retry = true;
}
} while (retry);
}
示例2: updateDataSerialized
import org.I0Itec.zkclient.DataUpdater; //导入方法依赖的package包/类
/**
* Updates data of an existing znode. The current content of the znode is passed to the {@link DataUpdater} that is
* passed into this method, which returns the new content. The new content is only written back to ZooKeeper if
* nobody has modified the given znode in between. If a concurrent change has been detected the new data of the
* znode is passed to the updater once again until the new contents can be successfully written back to ZooKeeper.
*
* @param <T>
* @param path The path of the znode.
* @param updater Updater that creates the new contents.
*/
public <T extends Object> void updateDataSerialized(String path, DataUpdater<T> updater) {
Stat stat = new Stat();
boolean retry;
do {
retry = false;
try {
T oldData = (T) readData(path, stat);
T newData = updater.update(oldData);
writeData(path, newData, stat.getVersion());
} catch (ZkBadVersionException e) {
retry = true;
}
} while (retry);
}
示例3: update
import org.I0Itec.zkclient.DataUpdater; //导入方法依赖的package包/类
@Override
public boolean update(String path, DataUpdater<ZNRecord> updater, int options) {
ZNode zNode = _recordMap.get(path);
ZNRecord current = zNode != null ? zNode.getRecord() : null;
ZNRecord newRecord = updater.update(current);
if (newRecord != null) {
return set(path, newRecord, options);
}
return false;
}
示例4: update
import org.I0Itec.zkclient.DataUpdater; //导入方法依赖的package包/类
@Override
public boolean update(String path, DataUpdater<T> updater, int options) {
T newRecord = null;
boolean exceptionDuringUpdater = false;
try {
newRecord = updater.update(pathToRecords.get(path));
} catch (Exception e) {
exceptionDuringUpdater = true;
}
if (exceptionDuringUpdater) {
return false;
} else {
return setAndNotify(path, newRecord);
}
}