Package org.apache.curator.framework.recipes.atomic

Examples of org.apache.curator.framework.recipes.atomic.DistributedAtomicInteger


        return count;
    }

    private int adjustAndGet(String userId, Direction direction) {
        RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES);
        DistributedAtomicInteger distributedAtomicInteger = new DistributedAtomicInteger(curatorFramework, counterPath(userId), retryPolicy);

        try {
            distributedAtomicInteger.initialize(0); // this will respect an existing value but set uninitialized values to 0
        } catch (Exception e) {
            throw new LumifyException("failed to initialize counter for " + userId);
        }

        try {
            AtomicValue<Integer> count = direction == Direction.INCREMENT ? distributedAtomicInteger.increment() : distributedAtomicInteger.decrement();
            if (count.succeeded()) {
                return count.postValue();
            } else {
                throw new LumifyException("failed to " + direction + " counter for " + userId);
            }
View Full Code Here


    this.alphabet = buildAlphabet();
  }

  @Override
  public void start() {
    this.distributedGenerator = new DistributedAtomicInteger(curator, COUNTER_PATH, new RetryOneTime(1));
  }
View Full Code Here

TOP

Related Classes of org.apache.curator.framework.recipes.atomic.DistributedAtomicInteger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.