Package org.kiwiproject.consul
Class KeyValueClient
java.lang.Object
org.kiwiproject.consul.KeyValueClient
HTTP Client for /v1/kv/ endpoints.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanacquireLock(String key, String session) Acquire a lock for a given key.booleanacquireLock(String key, String value, String session) Acquire a lock for a given key.voidDeletes a specified key.voiddeleteKey(String key, DeleteOptions deleteOptions) Deletes a specified key.voiddeleteKeys(String key) Deletes a specified key and any below it.Retrieves aConsulResponsewith theValuefor a specific key from the key/value storegetConsulResponseWithValue(String key, QueryOptions queryOptions) Returns aConsulResponsefor a specific key from the kv store.Retrieves aConsulResponsewith a list ofValueobjects along with consul response headers for a specific key from the key/value store.getConsulResponseWithValues(String key, QueryOptions queryOptions) Retrieves aConsulResponsewith a list ofValueobjects along with consul response headers for a specific key from the key/value store.Retrieves a list of matching keys for the given key.Retrieves a list of matching keys for the given key, limiting the prefix of keys returned, only up to the given separator.getKeys(String key, String separator, QueryOptions queryOptions) Retrieves a list of matching keys for the given key.getKeys(String key, QueryOptions queryOptions) Retrieves a list of matching keys for the given key.getSession(String key) Retrieves a session string for a specific key from the key/value store.Retrieves aValuefor a specific key from the key/value store.getValue(String key, QueryOptions queryOptions) Retrieves aValuefor a specific key from the key/value store.voidgetValue(String key, QueryOptions queryOptions, ConsulResponseCallback<Optional<Value>> callback) Asynchronously retrieves aValuefor a specific key from the key/value store.getValueAsString(String key) Retrieves a string value for a specific key from the key/value store.getValueAsString(String key, Charset charset) Retrieves a string value for a specific key from the key/value store.Retrieves a list ofValueobjects for a specific key from the key/value store.getValues(String key, QueryOptions queryOptions) Retrieves a list ofValueobjects for a specific key from the key/value store.voidgetValues(String key, QueryOptions queryOptions, ConsulResponseCallback<List<Value>> callback) Asynchronously retrieves a list ofValueobjects for a specific key from the key/value store.getValuesAsString(String key) Retrieves a list of string values for a specific key from the key/value store.getValuesAsString(String key, Charset charset) Retrieves a list of string values for a specific key from the key/value store.performTransaction(Operation... operations) Performs a Consul transaction.performTransaction(TransactionOptions transactionOptions, Operation... operations) Performs a Consul transaction.booleanPuts a null value into the key/value store.booleanputValue(String key, byte[] value, long flags, PutOptions putOptions) Puts a value into the key/value store.booleanPuts a value into the key/value store.booleanPuts a value into the key/value store.booleanPuts a value into the key/value store.booleanputValue(String key, String value, long flags, PutOptions putOptions) Puts a value into the key/value store.booleanputValue(String key, String value, long flags, PutOptions putOptions, Charset charset) Puts a value into the key/value store.booleanPuts a value into the key/value store.booleanreleaseLock(String key, String sessionId) Releases the lock for a given service and session.
-
Field Details
-
NOT_FOUND_404
public static final int NOT_FOUND_404- See Also:
-
http
-
-
Method Details
-
getValue
Retrieves aValuefor a specific key from the key/value store.GET /v1/kv/{key}
- Parameters:
key- The key to retrieve.- Returns:
- An
Optionalcontaining the value orOptional.empty()
-
getConsulResponseWithValue
Retrieves aConsulResponsewith theValuefor a specific key from the key/value store- Parameters:
key- The key to retrieve- Returns:
- An
Optionalcontaining theConsulResponseorOptional.empty()
-
getValue
Retrieves aValuefor a specific key from the key/value store.GET /v1/kv/{key}
- Parameters:
key- The key to retrieve.queryOptions- The query options.- Returns:
- An
Optionalcontaining the value orOptional.empty()
-
getConsulResponseWithValue
public Optional<ConsulResponse<Value>> getConsulResponseWithValue(String key, QueryOptions queryOptions) Returns aConsulResponsefor a specific key from the kv store. Contains the consul response headers along with the configuration value.GET /v1/kv/{key}
- Parameters:
key- The key to retrieve.queryOptions- The query options.- Returns:
- An
Optionalcontaining the ConsulResponse orOptional.empty()
-
getValue
public void getValue(String key, QueryOptions queryOptions, ConsulResponseCallback<Optional<Value>> callback) Asynchronously retrieves aValuefor a specific key from the key/value store.GET /v1/kv/{key}
- Parameters:
key- The key to retrieve.queryOptions- The query options.callback- Callback implemented by callee to handle results.
-
getValues
Retrieves a list ofValueobjects for a specific key from the key/value store.GET /v1/kv/{key}?recurse
- Parameters:
key- The key to retrieve.- Returns:
- A list of zero to many
Valueobjects.
-
getConsulResponseWithValues
Retrieves aConsulResponsewith a list ofValueobjects along with consul response headers for a specific key from the key/value store.GET /v1/kv/{key}?recurse
- Parameters:
key- The key to retrieve.- Returns:
- A
ConsulResponsewith a list of zero to manyValueobjects and consul response headers.
-
getValues
Retrieves a list ofValueobjects for a specific key from the key/value store.GET /v1/kv/{key}?recurse
- Parameters:
key- The key to retrieve.queryOptions- The query options.- Returns:
- A list of zero to many
Valueobjects.
-
getConsulResponseWithValues
public ConsulResponse<List<Value>> getConsulResponseWithValues(String key, QueryOptions queryOptions) Retrieves aConsulResponsewith a list ofValueobjects along with consul response headers for a specific key from the key/value store.GET /v1/kv/{key}?recurse
- Parameters:
key- The key to retrieve.queryOptions- The query options to use.- Returns:
- A
ConsulResponsewith a list of zero to manyValueobjects and consul response headers.
-
getValues
public void getValues(String key, QueryOptions queryOptions, ConsulResponseCallback<List<Value>> callback) Asynchronously retrieves a list ofValueobjects for a specific key from the key/value store.GET /v1/kv/{key}?recurse
- Parameters:
key- The key to retrieve.queryOptions- The query options.callback- Callback implemented by callee to handle results.
-
getValueAsString
Retrieves a string value for a specific key from the key/value store.GET /v1/kv/{key}
- Parameters:
key- The key to retrieve.- Returns:
- An
Optionalcontaining the value as a string orOptional.empty()
-
getValueAsString
Retrieves a string value for a specific key from the key/value store.GET /v1/kv/{key}
- Parameters:
key- The key to retrieve.charset- The charset of the value- Returns:
- An
Optionalcontaining the value as a string orOptional.empty()
-
getValuesAsString
Retrieves a list of string values for a specific key from the key/value store.GET /v1/kv/{key}?recurse
- Parameters:
key- The key to retrieve.- Returns:
- A list of zero to many string values.
-
getValuesAsString
Retrieves a list of string values for a specific key from the key/value store.GET /v1/kv/{key}?recurse
- Parameters:
key- The key to retrieve.charset- The charset of the value- Returns:
- A list of zero to many string values.
-
putValue
Puts a null value into the key/value store.- Parameters:
key- The key to use as index.- Returns:
trueif the value was successfully indexed.
-
putValue
Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.- Returns:
trueif the value was successfully indexed.
-
putValue
Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.charset- theCharsetto use- Returns:
trueif the value was successfully indexed.
-
putValue
Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.flags- The flags for this key.- Returns:
trueif the value was successfully indexed.
-
putValue
Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.flags- The flags for this key.charset- theCharsetto use- Returns:
trueif the value was successfully indexed.
-
putValue
Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.flags- The flags for this key.putOptions- PUT options (e.g. wait, acquire).- Returns:
trueif the value was successfully indexed.
-
putValue
public boolean putValue(String key, String value, long flags, PutOptions putOptions, Charset charset) Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.flags- The flags for this key.putOptions- PUT options (e.g. wait, acquire).charset- theCharsetto use- Returns:
trueif the value was successfully indexed.
-
putValue
Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.flags- The flags for this key.putOptions- PUT options (e.g. wait, acquire).- Returns:
trueif the value was successfully indexed.
-
getKeys
Retrieves a list of matching keys for the given key.GET /v1/kv/{key}?keys
- Parameters:
key- The key to retrieve.- Returns:
- A list of zero to many keys.
-
getKeys
Retrieves a list of matching keys for the given key.GET /v1/kv/{key}?keys
- Parameters:
key- The key to retrieve.queryOptions- The query options.- Returns:
- A list of zero to many keys.
-
getKeys
Retrieves a list of matching keys for the given key, limiting the prefix of keys returned, only up to the given separator.GET /v1/kv/{key}?keys&separator={separator}- Parameters:
key- The key to retrieve.separator- The separator used to limit the prefix of keys returned.- Returns:
- A list of zero to many keys.
-
getKeys
Retrieves a list of matching keys for the given key.GET /v1/kv/{key}?keys&separator={separator}- Parameters:
key- The key to retrieve.separator- The separator used to limit the prefix of keys returned.queryOptions- The query options.- Returns:
- A list of zero to many keys.
-
deleteKey
Deletes a specified key.DELETE /v1/kv/{key}
- Parameters:
key- The key to delete.
-
deleteKeys
Deletes a specified key and any below it.DELETE /v1/kv/{key}?recurse
- Parameters:
key- The key to delete.
-
deleteKey
Deletes a specified key.DELETE /v1/kv/{key}
- Parameters:
key- The key to delete.deleteOptions- DELETE options (e.g., recurse, cas)
-
acquireLock
Acquire a lock for a given key.PUT /v1/kv/{key}?acquire={session}
- Parameters:
key- The key to acquire the lock.session- The session to acquire lock.- Returns:
- true if the lock is acquired successfully, false otherwise.
-
acquireLock
Acquire a lock for a given key.PUT /v1/kv/{key}?acquire={session}
- Parameters:
key- The key to acquire the lock.session- The session to acquire lock.value- key value (usually application-specific info about the lock requester)- Returns:
- true if the lock is acquired successfully, false otherwise.
-
getSession
Retrieves a session string for a specific key from the key/value store.GET /v1/kv/{key}
- Parameters:
key- The key to retrieve.- Returns:
- An
Optionalcontaining the value as a string orOptional.empty()
-
releaseLock
Releases the lock for a given service and session.GET /v1/kv/{key}?release={sessionId}
- Parameters:
key- identifying the service.sessionId- the session ID- Returns:
SessionInfo.
-
performTransaction
Performs a Consul transaction.PUT /v1/tx
- Parameters:
operations- A list of KV operations.- Returns:
- A
ConsulResponsecontaining results and potential errors.
-
performTransaction
public ConsulResponse<TxResponse> performTransaction(TransactionOptions transactionOptions, Operation... operations) Performs a Consul transaction.PUT /v1/tx
- Parameters:
transactionOptions- transaction options (e.g. dc, consistency).operations- A list of KV operations.- Returns:
- A
ConsulResponsecontaining results and potential errors.
-
getNetworkTimeoutConfig
-
getConfig
-
getEventHandler
-