org.apache.curator.framework.recipes.atomic.DistributedAtomicInteger Java Examples
The following examples show how to use
org.apache.curator.framework.recipes.atomic.DistributedAtomicInteger.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DistAtomicIntTest.java From BigData-In-Practice with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { for (int i = 0; i < clientNums; i++) { String name = "client#" + i; new Thread(new Runnable() { @Override public void run() { try { CuratorFramework client = ZKUtils.getClient(); client.start(); DistributedAtomicInteger atomicInteger = new DistributedAtomicInteger(client, distAtomicPath, new RetryNTimes(3, 1000)); for (int j = 0; j < 10; j++) { AtomicValue<Integer> rc = atomicInteger.add(1); System.out.println(name + " Result: " + rc.succeeded() + ", postValue: " + rc.postValue()); Thread.sleep(100); } } catch (Exception e) { e.printStackTrace(); } finally { countDownLatch.countDown(); } } }).start(); } countDownLatch.await(); }
Example #2
Source File: ZookeeperRegistryCenter.java From paascloud-master with Apache License 2.0 | 5 votes |
/** * Increment. * * @param path the path * @param retryNTimes the retry n times */ @Override public void increment(String path, RetryNTimes retryNTimes) { try { distributedAtomicInteger = new DistributedAtomicInteger(client, path, retryNTimes); distributedAtomicInteger.increment(); } catch (Exception e) { log.error("increment={}", e.getMessage(), e); } }
Example #3
Source File: ZookeeperRegistryCenter.java From paascloud-master with Apache License 2.0 | 5 votes |
/** * Gets atomic value. * * @param path the path * @param retryNTimes the retry n times * * @return the atomic value */ @Override public AtomicValue<Integer> getAtomicValue(String path, RetryNTimes retryNTimes) { try { distributedAtomicInteger = new DistributedAtomicInteger(client, path, retryNTimes); return distributedAtomicInteger.get(); } catch (Exception e) { log.error("getAtomicValue={}", e.getMessage(), e); } return null; }
Example #4
Source File: ExecutorIdGenerator.java From Singularity with Apache License 2.0 | 4 votes |
public void start() { this.distributedGenerator = new DistributedAtomicInteger(curator, COUNTER_PATH, new RetryOneTime(1)); }