aboutsummaryrefslogtreecommitdiffstats
path: root/zkfacade
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@verizonmedia.com>2019-02-13 21:45:26 +0100
committerValerij Fredriksen <valerijf@verizonmedia.com>2019-02-14 14:09:02 +0100
commit28740d3322e3f3d5ea7d7456c13dbcf80e8c0c7d (patch)
treece343c7607b06e77d9deeba6e0df866c83e307dc /zkfacade
parent28f9beb798831c3f964d648e5507b897b798e5db (diff)
Pass provision indexes to host provisioner
Diffstat (limited to 'zkfacade')
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java37
1 files changed, 15 insertions, 22 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java
index 3d5a2eff583..dd49b2595a4 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/recipes/CuratorCounter.java
@@ -21,39 +21,32 @@ public class CuratorCounter {
this.counterPath = counterPath;
}
- /**
- * Atomically increment and return resulting value.
- *
- * @return the resulting value
- * @throws IllegalStateException if increment fails
- */
- public synchronized long next() {
- try {
- AtomicValue<Long> value = counter.increment();
- if (!value.succeeded()) {
- throw new IllegalStateException("Increment did not succeed");
- }
- return value.postValue();
- } catch (Exception e) {
- throw new IllegalStateException("Unable to get next value", e);
- }
+ /** Convenience method for {@link #add(long)} with 1 */
+ public long next() {
+ return add(1L);
+ }
+
+ /** Convenience method for {@link #add(long)} with -1 */
+ public long previous() {
+ return add(-1L);
}
/**
- * Atomically decrement and return the resulting value.
+ * Atomically add and return resulting value.
*
+ * @param delta value to add, may be negative
* @return the resulting value
- * @throws IllegalStateException if decrement fails
+ * @throws IllegalStateException if addition fails
*/
- public synchronized long previous() {
+ public synchronized long add(long delta) {
try {
- AtomicValue<Long> value = counter.subtract(1L);
+ AtomicValue<Long> value = counter.add(delta);
if (!value.succeeded()) {
- throw new IllegalStateException("Decrement did not succeed");
+ throw new IllegalStateException("Add did not succeed");
}
return value.postValue();
} catch (Exception e) {
- throw new IllegalStateException("Unable to get previous value", e);
+ throw new IllegalStateException("Unable to add value", e);
}
}