Package com.orbitz.consul
Class KeyValueClient
- java.lang.Object
-
- com.orbitz.consul.KeyValueClient
-
public class KeyValueClient extends java.lang.ObjectHTTP Client for /v1/kv/ endpoints.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceKeyValueClient.ApiRetrofit API interface.
-
Field Summary
Fields Modifier and Type Field Description protected Httphttpstatic intNOT_FOUND_404
-
Method Summary
Modifier and Type Method Description booleanacquireLock(java.lang.String key, java.lang.String session)Aquire a lock for a given key.booleanacquireLock(java.lang.String key, java.lang.String value, java.lang.String session)Aquire a lock for a given key.voiddeleteKey(java.lang.String key)Deletes a specified key.voiddeleteKey(java.lang.String key, DeleteOptions deleteOptions)Deletes a specified key.voiddeleteKeys(java.lang.String key)Deletes a specified key and any below it.ClientConfiggetConfig()java.util.Optional<ConsulResponse<Value>>getConsulResponseWithValue(java.lang.String key)Retrieves aConsulResponsewith theValuefor a spefici key from the key/value storejava.util.Optional<ConsulResponse<Value>>getConsulResponseWithValue(java.lang.String key, QueryOptions queryOptions)Returns aConsulResponsefor a specific key from the kv store.ConsulResponse<java.util.List<Value>>getConsulResponseWithValues(java.lang.String key)Retrieves aConsulResponsewith a list ofValueobjects along with consul response headers for a specific key from the key/value store.ConsulResponse<java.util.List<Value>>getConsulResponseWithValues(java.lang.String key, QueryOptions queryOptions)Retrieves aConsulResponsewith a list ofValueobjects along with consul response headers for a specific key from the key/value store.ClientEventHandlergetEventHandler()java.util.List<java.lang.String>getKeys(java.lang.String key)Retrieves a list of matching keys for the given key.java.util.List<java.lang.String>getKeys(java.lang.String key, QueryOptions queryOptions)Retrieves a list of matching keys for the given key.java.util.Optional<java.lang.String>getSession(java.lang.String key)Retrieves a session string for a specific key from the key/value store.java.util.Optional<Value>getValue(java.lang.String key)Retrieves aValuefor a specific key from the key/value store.java.util.Optional<Value>getValue(java.lang.String key, QueryOptions queryOptions)Retrieves aValuefor a specific key from the key/value store.voidgetValue(java.lang.String key, QueryOptions queryOptions, ConsulResponseCallback<java.util.Optional<Value>> callback)Asynchronously retrieves aValuefor a specific key from the key/value store.java.util.Optional<java.lang.String>getValueAsString(java.lang.String key)Retrieves a string value for a specific key from the key/value store.java.util.Optional<java.lang.String>getValueAsString(java.lang.String key, java.nio.charset.Charset charset)Retrieves a string value for a specific key from the key/value store.java.util.List<Value>getValues(java.lang.String key)Retrieves a list ofValueobjects for a specific key from the key/value store.java.util.List<Value>getValues(java.lang.String key, QueryOptions queryOptions)Retrieves a list ofValueobjects for a specific key from the key/value store.voidgetValues(java.lang.String key, QueryOptions queryOptions, ConsulResponseCallback<java.util.List<Value>> callback)Asynchronously retrieves a list ofValueobjects for a specific key from the key/value store.java.util.List<java.lang.String>getValuesAsString(java.lang.String key)Retrieves a list of string values for a specific key from the key/value store.java.util.List<java.lang.String>getValuesAsString(java.lang.String key, java.nio.charset.Charset charset)Retrieves a list of string values for a specific key from the key/value store.ConsulResponse<TxResponse>performTransaction(Operation... operations)Performs a Consul transaction.ConsulResponse<TxResponse>performTransaction(ConsistencyMode consistency, Operation... operations)Deprecated.ConsulResponse<TxResponse>performTransaction(TransactionOptions transactionOptions, Operation... operations)Performs a Consul transaction.booleanputValue(java.lang.String key)Puts a null value into the key/value store.booleanputValue(java.lang.String key, byte[] value, long flags, PutOptions putOptions)Puts a value into the key/value store.booleanputValue(java.lang.String key, java.lang.String value)Puts a value into the key/value store.booleanputValue(java.lang.String key, java.lang.String value, long flags)Puts a value into the key/value store.booleanputValue(java.lang.String key, java.lang.String value, long flags, PutOptions putOptions)Puts a value into the key/value store.booleanputValue(java.lang.String key, java.lang.String value, long flags, PutOptions putOptions, java.nio.charset.Charset charset)Puts a value into the key/value store.booleanputValue(java.lang.String key, java.lang.String value, long flags, java.nio.charset.Charset charset)Puts a value into the key/value store.booleanputValue(java.lang.String key, java.lang.String value, java.nio.charset.Charset charset)Puts a value into the key/value store.booleanreleaseLock(java.lang.String key, java.lang.String sessionId)Releases the lock for a given service and session.
-
-
-
Field Detail
-
NOT_FOUND_404
public static final int NOT_FOUND_404
- See Also:
- Constant Field Values
-
http
protected final Http http
-
-
Method Detail
-
getValue
public java.util.Optional<Value> getValue(java.lang.String key)
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 or {@link Optional#empty()()}
-
getConsulResponseWithValue
public java.util.Optional<ConsulResponse<Value>> getConsulResponseWithValue(java.lang.String key)
Retrieves aConsulResponsewith theValuefor a spefici key from the key/value store- Parameters:
key- The key to retrieve- Returns:
- An
Optionalcontaining theConsulResponseor {@link Optional#empty()()}
-
getValue
public java.util.Optional<Value> getValue(java.lang.String key, QueryOptions queryOptions)
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 or {@link Optional#empty()()}
-
getConsulResponseWithValue
public java.util.Optional<ConsulResponse<Value>> getConsulResponseWithValue(java.lang.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(java.lang.String key, QueryOptions queryOptions, ConsulResponseCallback<java.util.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
public java.util.List<Value> getValues(java.lang.String key)
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
public ConsulResponse<java.util.List<Value>> getConsulResponseWithValues(java.lang.String key)
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
public java.util.List<Value> getValues(java.lang.String key, QueryOptions queryOptions)
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<java.util.List<Value>> getConsulResponseWithValues(java.lang.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(java.lang.String key, QueryOptions queryOptions, ConsulResponseCallback<java.util.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
public java.util.Optional<java.lang.String> getValueAsString(java.lang.String key)
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
public java.util.Optional<java.lang.String> getValueAsString(java.lang.String key, java.nio.charset.Charset charset)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
public java.util.List<java.lang.String> getValuesAsString(java.lang.String key)
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
public java.util.List<java.lang.String> getValuesAsString(java.lang.String key, java.nio.charset.Charset charset)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
public boolean putValue(java.lang.String key)
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
public boolean putValue(java.lang.String key, java.lang.String value)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
public boolean putValue(java.lang.String key, java.lang.String value, java.nio.charset.Charset charset)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
public boolean putValue(java.lang.String key, java.lang.String value, long flags)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
public boolean putValue(java.lang.String key, java.lang.String value, long flags, java.nio.charset.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.- Returns:
trueif the value was successfully indexed.
-
putValue
public boolean putValue(java.lang.String key, java.lang.String value, long flags, PutOptions putOptions)Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.putOptions- PUT options (e.g. wait, acquire).- Returns:
trueif the value was successfully indexed.
-
putValue
public boolean putValue(java.lang.String key, java.lang.String value, long flags, PutOptions putOptions, java.nio.charset.Charset charset)Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.putOptions- PUT options (e.g. wait, acquire).- Returns:
trueif the value was successfully indexed.
-
putValue
public boolean putValue(java.lang.String key, byte[] value, long flags, PutOptions putOptions)Puts a value into the key/value store.- Parameters:
key- The key to use as index.value- The value to index.putOptions- PUT options (e.g. wait, acquire).- Returns:
trueif the value was successfully indexed.
-
getKeys
public java.util.List<java.lang.String> getKeys(java.lang.String key)
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
public java.util.List<java.lang.String> getKeys(java.lang.String key, QueryOptions queryOptions)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.
-
deleteKey
public void deleteKey(java.lang.String key)
Deletes a specified key. DELETE /v1/kv/{key}- Parameters:
key- The key to delete.
-
deleteKeys
public void deleteKeys(java.lang.String key)
Deletes a specified key and any below it. DELETE /v1/kv/{key}?recurse- Parameters:
key- The key to delete.
-
deleteKey
public void deleteKey(java.lang.String key, DeleteOptions deleteOptions)Deletes a specified key. DELETE /v1/kv/{key}- Parameters:
key- The key to delete.deleteOptions- DELETE options (e.g. recurse, cas)
-
acquireLock
public boolean acquireLock(java.lang.String key, java.lang.String session)Aquire 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
public boolean acquireLock(java.lang.String key, java.lang.String value, java.lang.String session)Aquire 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
public java.util.Optional<java.lang.String> getSession(java.lang.String key)
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
public boolean releaseLock(java.lang.String key, java.lang.String sessionId)Releases the lock for a given service and session. GET /v1/kv/{key}?release={sessionId}- Parameters:
key- identifying the service.sessionId-- Returns:
SessionInfo.
-
performTransaction
public ConsulResponse<TxResponse> performTransaction(Operation... operations)
Performs a Consul transaction. PUT /v1/tx- Parameters:
operations- A list of KV operations.- Returns:
- A
ConsulResponsecontaining results and potential errors.
-
performTransaction
@Deprecated public ConsulResponse<TxResponse> performTransaction(ConsistencyMode consistency, Operation... operations)
Deprecated.Performs a Consul transaction. PUT /v1/tx- Parameters:
consistency- The consistency to use for the transaction.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.
-
getConfig
public ClientConfig getConfig()
-
getEventHandler
public ClientEventHandler getEventHandler()
-
-