本文整理汇总了Java中org.apache.curator.framework.recipes.atomic.AtomicValue.preValue方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicValue.preValue方法的具体用法?Java AtomicValue.preValue怎么用?Java AtomicValue.preValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.recipes.atomic.AtomicValue
的用法示例。
在下文中一共展示了AtomicValue.preValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateMaxTimestamp
import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
@Override
public void updateMaxTimestamp(long previousMaxTimestamp, long newMaxTimestamp) throws IOException {
if (newMaxTimestamp < 0) {
LOG.error("Negative value received for maxTimestamp: {}", newMaxTimestamp);
throw new IllegalArgumentException();
}
if (newMaxTimestamp <= previousMaxTimestamp) {
LOG.error("maxTimestamp {} <= previousMaxTimesamp: {}", newMaxTimestamp, previousMaxTimestamp);
throw new IllegalArgumentException();
}
AtomicValue<Long> compareAndSet;
try {
compareAndSet = timestamp.compareAndSet(previousMaxTimestamp, newMaxTimestamp);
} catch (Exception e) {
throw new IOException("Problem setting timestamp in ZK", e);
}
if (!compareAndSet.succeeded()) { // We have to explicitly check for success (See Curator doc)
throw new IOException("GetAndSet operation for storing timestamp in ZK did not succeed "
+ compareAndSet.preValue() + " " + compareAndSet.postValue());
}
}
示例2: getRequests
import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
/**
* Return the shared counter.
* @return
* @throws Exception
*/
private long getRequests() throws Exception {
long contador = 0;
AtomicValue<Long> value = this.zkw.getCounter().get();
if (value.succeeded()) {
contador = value.postValue();
}
else {
contador = value.preValue();
}
return contador;
}
示例3: allocateUniqueIdBlock
import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
@Override
public IdBlock allocateUniqueIdBlock(long range) {
try {
AtomicValue<Long> result = null;
do {
result = distributedIdCounter.add(range);
} while (result == null || !result.succeeded());
return new IdBlock(result.preValue(), range);
} catch (Exception e) {
log.error("Error allocating ID block");
}
return null;
}