summaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java
diff options
context:
space:
mode:
Diffstat (limited to 'configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java
new file mode 100644
index 00000000000..589363467b0
--- /dev/null
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelGenerationCounter.java
@@ -0,0 +1,40 @@
+// Copyright 2016 Yahoo Inc. 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.recipes.CuratorCounter;
+import com.yahoo.vespa.curator.Curator;
+
+/**
+ * Distributed global generation counter for the super model.
+ *
+ * @author lulf
+ * @since 5.9
+ */
+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.getAbsolute());
+ }
+
+ /**
+ * 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();
+ }
+}