当前位置: 首页>>代码示例>>Java>>正文


Java AtomicValue.preValue方法代码示例

本文整理汇总了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());
    }

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:24,代码来源:ZKTimestampStorage.java

示例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;
}
 
开发者ID:cleuton,项目名称:servkeeper,代码行数:17,代码来源:ServerResource.java

示例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;
}
 
开发者ID:opennetworkinglab,项目名称:spring-open,代码行数:15,代码来源:ZookeeperRegistry.java


注:本文中的org.apache.curator.framework.recipes.atomic.AtomicValue.preValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。