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


Java AtomicValue.succeeded方法代码示例

本文整理汇总了Java中org.apache.curator.framework.recipes.atomic.AtomicValue.succeeded方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicValue.succeeded方法的具体用法?Java AtomicValue.succeeded怎么用?Java AtomicValue.succeeded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.framework.recipes.atomic.AtomicValue的用法示例。


在下文中一共展示了AtomicValue.succeeded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, Exception {
	try (TestingServer server = new TestingServer()) {
		CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
		client.start();

		List<DistributedAtomicLong> examples = Lists.newArrayList();
		ExecutorService service = Executors.newFixedThreadPool(QTY);
		for (int i = 0; i < QTY; ++i) {
			final DistributedAtomicLong count = new DistributedAtomicLong(client, PATH, new RetryNTimes(10, 10));
			
			examples.add(count);
			Callable<Void> task = new Callable<Void>() {
				@Override
				public Void call() throws Exception {
					try {
						//Thread.sleep(rand.nextInt(1000));
						AtomicValue<Long> value = count.increment();
						//AtomicValue<Long> value = count.decrement();
						//AtomicValue<Long> value = count.add((long)rand.nextInt(20));
						System.out.println("succeed: " + value.succeeded());
						if (value.succeeded())
							System.out.println("Increment: from " + value.preValue() + " to " + value.postValue());
					} catch (Exception e) {
						e.printStackTrace();
					}

					return null;
				}
			};
			service.submit(task);
		}

		service.shutdown();
		service.awaitTermination(10, TimeUnit.MINUTES);
	}

}
 
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:38,代码来源:DistributedAtomicLongExample.java

示例4: nextId

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public long nextId(final String namespace) {
    final String[] paths = calcPathIdAndPathLock(namespace);
    final String pathId = paths[0];
    final String pathLock = paths[1];

    RetryPolicy retryPolicyMutex = new BoundedExponentialBackoffRetry(10, 1000, 5);
    PromotedToLock promotedToLock = PromotedToLock.builder().retryPolicy(retryPolicyMutex)
            .lockPath(pathLock).build();
    RetryPolicy retryPolicyOptimistic = new RetryNTimes(3, 100);
    DistributedAtomicLong dal = new DistributedAtomicLong(curatorFramework, pathId,
            retryPolicyOptimistic, promotedToLock);
    semaphore.acquireUninterruptibly();
    try {
        AtomicValue<Long> value = dal.increment();
        if (value != null && value.succeeded()) {
            return value.postValue();
        }
        return -1;
    } catch (Exception e) {
        throw e instanceof IdException ? (IdException) e : new IdException(e);
    } finally {
        semaphore.release();
    }
}
 
开发者ID:DDTH,项目名称:ddth-id,代码行数:29,代码来源:ZookeeperIdGenerator.java

示例5: currentId

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public long currentId(final String namespace) {
    final String[] paths = calcPathIdAndPathLock(namespace);
    final String pathId = paths[0];
    final String pathLock = paths[1];

    RetryPolicy retryPolicyMutex = new BoundedExponentialBackoffRetry(10, 1000, 5);
    PromotedToLock promotedToLock = PromotedToLock.builder().retryPolicy(retryPolicyMutex)
            .lockPath(pathLock).build();
    RetryPolicy retryPolicyOptimistic = new RetryNTimes(3, 100);
    DistributedAtomicLong dal = new DistributedAtomicLong(curatorFramework, pathId,
            retryPolicyOptimistic, promotedToLock);
    try {
        AtomicValue<Long> value = dal.get();
        if (value != null && value.succeeded()) {
            return value.postValue();
        }
        throw new IdException("Operation was not successful!");
    } catch (Exception e) {
        throw e instanceof IdException ? (IdException) e : new IdException(e);
    }
}
 
开发者ID:DDTH,项目名称:ddth-id,代码行数:26,代码来源:ZookeeperIdGenerator.java

示例6: getIncrementValue

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
/**
 * 获得分布式自增变量
 * @param path
 * @return
 * @throws Exception
 */
public Long getIncrementValue(String path) throws Exception {
    DistributedAtomicLong atomicId = new DistributedAtomicLong(client, path, new RetryNTimes(32,1000));
    AtomicValue<Long> rc = atomicId.get();
    if (rc.succeeded()) {
        logger.debug("getIncrementValue({}) success! get: {}.", path, rc.postValue());
    } else {
        logger.warn("getIncrementValue({}) failed! get: {}.", path, rc.postValue());
    }
    return rc.postValue();
}
 
开发者ID:BriData,项目名称:DBus,代码行数:17,代码来源:ZkService.java

示例7: incrementAndGetValue

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
/**
 * 自增并获得,自增后的变量
 * @param path
 * @return
 * @throws Exception
 */
public Long incrementAndGetValue(String path) throws Exception {
    DistributedAtomicLong atomicId = new DistributedAtomicLong(client, path, new RetryNTimes(32,1000));
    AtomicValue<Long> rc = atomicId.increment();
    if (rc.succeeded()) {
        logger.info("incrementAndGetValue({}) success! before: {}, after: {}.", path, rc.preValue(), rc.postValue());
    } else {
        logger.warn("incrementAndGetValue({}) failed! before: {}, after: {}.", path, rc.preValue(), rc.postValue());
    }
    return rc.postValue();
}
 
开发者ID:BriData,项目名称:DBus,代码行数:17,代码来源:ZkService.java

示例8: addInSync

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
private static void addInSync(String path, long delta){
    try {
        ZKPaths.mkdirs(CURATOR_FRAMEWORK.getZookeeperClient().getZooKeeper(), path);
        COUNTERS.putIfAbsent(path, new DistributedAtomicLong(CURATOR_FRAMEWORK, path, RETRY_N_TIMES));
        DistributedAtomicLong counter = COUNTERS.get(path);
        AtomicValue<Long> returnValue = counter.add(delta);
        while (!returnValue.succeeded()) {
            returnValue = counter.add(delta);
        }
    }catch (Exception e){
        LOGGER.error("addInSync "+delta+" failed for "+path, e);
    }
}
 
开发者ID:ysc,项目名称:counter,代码行数:14,代码来源:AtomicCounter.java

示例9: subtract

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
private static void subtract(String path, long delta){
    try {
        ZKPaths.mkdirs(CURATOR_FRAMEWORK.getZookeeperClient().getZooKeeper(), path);
        COUNTERS.putIfAbsent(path, new DistributedAtomicLong(CURATOR_FRAMEWORK, path, RETRY_N_TIMES));
        DistributedAtomicLong counter = COUNTERS.get(path);
        AtomicValue<Long> returnValue = counter.subtract(delta);
        while (!returnValue.succeeded()) {
            returnValue = counter.subtract(delta);
        }
    }catch (Exception e){
        LOGGER.error("subtract "+delta+" failed for "+path, e);
    }
}
 
开发者ID:ysc,项目名称:counter,代码行数:14,代码来源:AtomicCounter.java

示例10: getMaxTimestamp

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
@Override
public long getMaxTimestamp() throws IOException {

    AtomicValue<Long> atomicValue;
    try {
        atomicValue = timestamp.get();
    } catch (Exception e) {
        throw new IOException("Problem getting data from ZK", e);
    }
    if (!atomicValue.succeeded()) { // We have to explicitly check for success (See Curator doc)
        throw new IOException("Get operation to obtain timestamp from ZK did not succeed");
    }
    return atomicValue.postValue();

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

示例11: next

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
/**
 * Atomically increment and return resulting value.
 *
 * @return the resulting value
 * @throws IllegalStateException if increment fails
 */
public synchronized long next() {
    try {
        AtomicValue<Long> value = counter.increment();
        if (!value.succeeded()) {
            throw new IllegalStateException("Increment did not succeed");
        }
        return value.postValue();
    } catch (Exception e) {
        throw new IllegalStateException("Unable to get next value", e);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:18,代码来源:CuratorCounter.java

示例12: previous

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
/**
 * Atomically decrement and return the resulting value.
 *
 * @return the resulting value
 * @throws IllegalStateException if decrement fails
 */
public synchronized long previous() {
    try {
        AtomicValue<Long> value = counter.subtract(1L);
        if (!value.succeeded()) {
            throw new IllegalStateException("Decrement did not succeed");
        }
        return value.postValue();
    } catch (Exception e) {
        throw new IllegalStateException("Unable to get previous value", e);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:18,代码来源:CuratorCounter.java

示例13: get

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
public long get() {
    try {
        AtomicValue<Long> value = counter.get();
        if (!value.succeeded()) {
            throw new RuntimeException("Get did not succeed");
        }
        return value.postValue();
    } catch (Exception e) {
        throw new RuntimeException("Unable to get value", e);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:12,代码来源:CuratorCounter.java

示例14: uniqueNumber

import org.apache.curator.framework.recipes.atomic.AtomicValue; //导入方法依赖的package包/类
public long uniqueNumber() {
    // XXX Blocks of numbers.
    try {
        AtomicValue<Long> along = globalCounter.increment() ;
        if ( ! along.succeeded() ) {
            log.error("Failed: uniqueNumber") ;
            throw new LizardException("Failed to allocate a unique number") ;
        }
        //FmtLog.info(log, "Unique: %d -> %d", along.preValue(), along.postValue()) ;
        return along.postValue() ;
    }
    catch (Exception e) {
        throw new LizardException("Exception allocating a unique number", e) ;
    }
}
 
开发者ID:afs,项目名称:lizard,代码行数:16,代码来源:Cluster.java

示例15: 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.succeeded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。