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);
}