blob: ffc2089b0b3cf13b95927ee53c157eeaee8af486 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;
import com.yahoo.path.Path;
import com.yahoo.vespa.config.GenerationCounter;
import com.yahoo.vespa.curator.Curator;
import com.yahoo.vespa.curator.recipes.CuratorCounter;
/**
* Distributed global generation counter for the super model.
*
* @author Ulf Lilleengen
*/
public class SuperModelGenerationCounter implements GenerationCounter {
private static final Path counterPath = Path.fromString("/config/v2/RPC/superModelGeneration");
private final CuratorCounter counter;
public SuperModelGenerationCounter(Curator curator) {
this.counter = new CuratorCounter(curator, counterPath);
}
/**
* Increment counter and return next value. This method is thread safe and provides an atomic value
* across zookeeper clusters.
*
* @return incremented counter value.
*/
public synchronized long increment() {
return counter.next();
}
/**
* @return current counter value.
*/
public synchronized long get() {
return counter.get();
}
}
|