/** * 测试入口 */ public static void main(String[] args) throws Exception { client.start(); DistributedAtomicInteger atomicInteger = new DistributedAtomicInteger( client, path, new RetryNTimes(3, 1000)); int jia = new Random().nextInt(100); AtomicValue<Integer> rc = atomicInteger.add(jia); System.out.println("pre: " + rc.preValue()); System.out.println("add: " + jia); System.out.println("post: " + rc.postValue()); System.out.println("Result: " + rc.succeeded()); }
public ZkJobStatusUpdaterHandler(CuratorFramework client, String jobId) { String path = getGlobalZkPath(jobId); inputDone = new DistributedAtomicInteger(client, path + "/stats/inputDone", RETRY_POLICY); cancelled = new DistributedAtomicInteger(client, path + "/stats/cancelled", RETRY_POLICY); errors = new DistributedAtomicInteger(client, path + "/stats/errors", RETRY_POLICY); outputs = new DistributedAtomicInteger(client, path + "/stats/outputs", RETRY_POLICY); retries = new DistributedAtomicInteger(client, path + "/stats/retries", RETRY_POLICY); tasks = new DistributedAtomicInteger(client, path + "/stats/tasks", RETRY_POLICY); tasksDone = new DistributedAtomicInteger(client, path + "/stats/tasksDone", RETRY_POLICY); }
@Override public void start() { this.distributedGenerator = new DistributedAtomicInteger(curator, COUNTER_PATH, new RetryOneTime(1)); }