public boolean acquireLock(long maxWait, TimeUnit unit) { KeyValueClient kv = consul.keyValueClient(); sessionId = createSession(); Optional<Value> value = kv.getValue(path); if (kv.acquireLock(path, sessionId)) { return true; } BigInteger index = BigInteger.valueOf(value.get().getModifyIndex()); kv.getValue(path, QueryOptions.blockMinutes((int) unit.toMinutes(maxWait), index).build()); if (!kv.acquireLock(path, sessionId)) { destroySession(); return false; } else { return true; } }
private static QueryOptions watchDefaultParams(final BigInteger index, final int blockSeconds) { if (index == null) { return QueryOptions.BLANK; } else { return QueryOptions.blockSeconds(blockSeconds, index).build(); } }
/** * @return The computed-at-construction value of the {@code nodeMetaQuery} attribute */ @Override public List<String> getNodeMetaQuery() { return initShim != null ? initShim.getNodeMetaQuery() : nodeMetaQuery; }
@Override public final Map<String, Object> toQuery() { Map<String, Object> result = new HashMap<>(); optionallyAdd(result, "dc", getDc()); optionallyAdd(result, "cas", getCas()); optionallyAdd(result, "acquire", getAcquire()); optionallyAdd(result, "release", getRelease()); optionallyAdd(result, "token", getToken()); return result; } }
/** * Creates an immutable copy of a {@link PutOptions} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable PutOptions instance */ public static ImmutablePutOptions copyOf(PutOptions instance) { if (instance instanceof ImmutablePutOptions) { return (ImmutablePutOptions) instance; } return ImmutablePutOptions.builder() .from(instance) .build(); }
/** * Creates an immutable copy of a {@link DeleteOptions} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable DeleteOptions instance */ public static ImmutableDeleteOptions copyOf(DeleteOptions instance) { if (instance instanceof ImmutableDeleteOptions) { return (ImmutableDeleteOptions) instance; } return ImmutableDeleteOptions.builder() .from(instance) .build(); }
/** * @return The computed-at-construction value of the {@code tagsQuery} attribute */ @Override public List<String> getTagsQuery() { return initShim != null ? initShim.getTagsQuery() : tagsQuery; }
/** * Builds a new {@link ImmutableDeleteOptions ImmutableDeleteOptions}. * @return An immutable instance of DeleteOptions * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableDeleteOptions build() { return new ImmutableDeleteOptions(cas, recurse, datacenter); } }
/** * @return The computed-at-construction value of the {@code isBlocking} attribute */ @Override public boolean isBlocking() { return initShim != null ? initShim.isBlocking() : isBlocking; }
/** * Creates a builder for {@link ImmutableQueryOptions ImmutableQueryOptions}. * @return A new ImmutableQueryOptions builder */ public static ImmutableQueryOptions.Builder builder() { return new ImmutableQueryOptions.Builder(); }
/** * Creates a builder for {@link ImmutablePutOptions ImmutablePutOptions}. * @return A new ImmutablePutOptions builder */ public static ImmutablePutOptions.Builder builder() { return new ImmutablePutOptions.Builder(); }
/** * Builds a new {@link ImmutableQueryOptions ImmutableQueryOptions}. * @return An immutable instance of QueryOptions * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableQueryOptions build() { return ImmutableQueryOptions.validate(new ImmutableQueryOptions(this)); } }
/** * Builds a new {@link ImmutableEventOptions ImmutableEventOptions}. * @return An immutable instance of EventOptions * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableEventOptions build() { return new ImmutableEventOptions(datacenter, nodeFilter, serviceFilter, tagFilter); } }
/** * Creates a builder for {@link ImmutableTransactionOptions ImmutableTransactionOptions}. * @return A new ImmutableTransactionOptions builder */ public static ImmutableTransactionOptions.Builder builder() { return new ImmutableTransactionOptions.Builder(); }
/** * Creates a builder for {@link ImmutableEventOptions ImmutableEventOptions}. * @return A new ImmutableEventOptions builder */ public static ImmutableEventOptions.Builder builder() { return new ImmutableEventOptions.Builder(); }
/** * Creates a builder for {@link ImmutableDeleteOptions ImmutableDeleteOptions}. * @return A new ImmutableDeleteOptions builder */ public static ImmutableDeleteOptions.Builder builder() { return new ImmutableDeleteOptions.Builder(); }
/** * Builds a new {@link ImmutableTransactionOptions ImmutableTransactionOptions}. * @return An immutable instance of TransactionOptions * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableTransactionOptions build() { return new ImmutableTransactionOptions(this); } }
/** * @return The value of the {@code consistencyMode} attribute */ @Override public ConsistencyMode getConsistencyMode() { return initShim != null ? initShim.getConsistencyMode() : consistencyMode; }
/** * @return The computed-at-construction value of the {@code hasToken} attribute */ @Override public boolean hasToken() { return initShim != null ? initShim.hasToken() : hasToken; }
/** * Builds a new {@link ImmutablePutOptions ImmutablePutOptions}. * @return An immutable instance of PutOptions * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutablePutOptions build() { return new ImmutablePutOptions(cas, acquire, release, dc, token); } }