/** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure */ @Deprecated @JsonCreator static ImmutableOperation fromJson(Json json) { ImmutableOperation.Builder builder = ImmutableOperation.builder(); if (json.verb != null) { builder.verb(json.verb); } if (json.key != null) { builder.key(json.key); } if (json.value != null) { builder.value(json.value); } if (json.flags != null) { builder.flags(json.flags); } if (json.index != null) { builder.index(json.index); } if (json.session != null) { builder.session(json.session); } return builder.build(); }
/** * Returns {@code true} if the given session owned the lock, otherwise {@code false}. */ public static boolean unlockAndDelete(KeyValueClient kv, String key, String sessionId) { try { kv.performTransaction( ImmutableOperation.builder(Verb.UNLOCK).key(key).session(sessionId).build(), ImmutableOperation.builder(Verb.DELETE).key(key).build()); return true; } catch (ConsulException e) { if (e.getCode() == HTTP_CONFLICT) { return false; // didn't own lock; no worries } throw e; } }
/** * Creates an immutable copy of a {@link Operation} 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 Operation instance */ public static ImmutableOperation copyOf(Operation instance) { if (instance instanceof ImmutableOperation) { return (ImmutableOperation) instance; } return ImmutableOperation.builder() .from(instance) .build(); }