com.orbitz.consul
Class KeyValueClient

java.lang.Object
  extended by com.orbitz.consul.KeyValueClient

public class KeyValueClient
extends java.lang.Object

HTTP Client for /v1/kv/ endpoints.


Method Summary
 boolean acquireLock(java.lang.String key, java.lang.String session)
          Aquire a lock for a given key.
 boolean acquireLock(java.lang.String key, java.lang.String value, java.lang.String session)
          Aquire a lock for a given key.
 void deleteKey(java.lang.String key)
          Deletes a specified key.
 void deleteKeys(java.lang.String key)
          Deletes a specified key and any below it.
 java.util.List<java.lang.String> getKeys(java.lang.String key)
          Retrieves a list of matching keys for the given key.
 com.google.common.base.Optional<java.lang.String> getSession(java.lang.String key)
          Retrieves a session string for a specific key from the key/value store.
 com.google.common.base.Optional<Value> getValue(java.lang.String key)
          Retrieves a Value for a specific key from the key/value store.
 com.google.common.base.Optional<Value> getValue(java.lang.String key, QueryOptions queryOptions)
          Retrieves a Value for a specific key from the key/value store.
 void getValue(java.lang.String key, QueryOptions queryOptions, ConsulResponseCallback<java.util.List<Value>> callback)
          Asynchronously retrieves a Value for a specific key from the key/value store.
 com.google.common.base.Optional<java.lang.String> getValueAsString(java.lang.String key)
          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 of Value objects for a specific key from the key/value store.
 void getValues(java.lang.String key, QueryOptions queryOptions, ConsulResponseCallback<java.util.List<Value>> callback)
          Asynchronously retrieves a list of Value objects 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.
 boolean putValue(java.lang.String key, java.lang.String value)
          Puts a value into the key/value store.
 boolean putValue(java.lang.String key, java.lang.String value, long flags)
          Puts a value into the key/value store.
 boolean releaseLock(java.lang.String key, java.lang.String sessionId)
          Releases the lock for a given service and session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getValue

public com.google.common.base.Optional<Value> getValue(java.lang.String key)
Retrieves a Value for a specific key from the key/value store. GET /v1/kv/{key}

Parameters:
key - The key to retrieve.
Returns:
An Optional containing the value or Optional.absent()

getValue

public com.google.common.base.Optional<Value> getValue(java.lang.String key,
                                                       QueryOptions queryOptions)
Retrieves a Value for a specific key from the key/value store. GET /v1/kv/{key}

Parameters:
key - The key to retrieve.
queryOptions - The query options.
Returns:
An Optional containing the value or Optional.absent()

getValue

public void getValue(java.lang.String key,
                     QueryOptions queryOptions,
                     ConsulResponseCallback<java.util.List<Value>> callback)
Asynchronously retrieves a Value for 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 of Value objects 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 Value objects.

getValues

public void getValues(java.lang.String key,
                      QueryOptions queryOptions,
                      ConsulResponseCallback<java.util.List<Value>> callback)
Asynchronously retrieves a list of Value objects 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 com.google.common.base.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 Optional containing the value as a string or Optional.absent()

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.

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:
true if 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:
true if 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.

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.

acquireLock

public boolean acquireLock(java.lang.String key,
                           java.lang.String session)
Aquire a lock for a given key. PUT /v1/kv/?acquire=

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/?acquire=

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 com.google.common.base.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/

Parameters:
key - The key to retrieve.
Returns:
An Optional containing the value as a string or Optional.absent()

releaseLock

public boolean releaseLock(java.lang.String key,
                           java.lang.String sessionId)
Releases the lock for a given service and session. GET /v1/kv/?release=

Parameters:
key - identifying the service.
sessionId -
Returns:
SessionInfo.