org.apache.tamaya.etcd

## Class EtcdAccessor

- java.lang.Object
- - org.apache.tamaya.etcd.EtcdAccessor

-     public class EtcdAccessor
      extends Object

  Accessor for reading to or writing from an etcd endpoint.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `JOHNZON_SUPPORTS_COMMENTS_PROP` Property that make Johnzon accept commentc.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EtcdAccessor(String server)` Creates a new instance with the basic access url.
    `EtcdAccessor(String server, int timeout)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Map<String,String>` | `delete(String key)` Deletes a given key.
    `Map<String,String>` | `get(String key)` Ask etcd for a single key, value pair.
    `Map<String,String>` | `getProperties(String directory)` Get all properties for the given directory key recursively.
    `Map<String,String>` | `getProperties(String directory, boolean recursive)` Access all properties.
    `String` | `getUrl()` Access the server root URL used by this accessor.
    `String` | `getVersion()` Get the etcd server version.
    `Map<String,String>` | `set(String key, String value)` Creates/updates an entry in etcd without any ttl set.
    `Map<String,String>` | `set(String key, String value, Integer ttlSeconds)` Creates/updates an entry in etcd.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### JOHNZON_SUPPORTS_COMMENTS_PROP

          public static final String JOHNZON_SUPPORTS_COMMENTS_PROP

      Property that make Johnzon accept commentc.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### EtcdAccessor

          public EtcdAccessor(String server)

      Creates a new instance with the basic access url.
      Parameters:
        `server` - server url, e.g. `http://127.0.0.1:4001`, not null.

    - #### EtcdAccessor

          public EtcdAccessor(String server,
                      int timeout)

  - ### Method Detail

    - #### getVersion

          public String getVersion()

      Get the etcd server version.
      Returns:
        the etcd server version, never null.

    - #### get

          public Map<String,String> get(String key)

      Ask etcd for a single key, value pair. Hereby the response returned from etcd:

           {
           "action": "get",
           "node": {
           "createdIndex": 2,
           "key": "/message",
           "modifiedIndex": 2,
           "value": "Hello world"
           }
           }

      is mapped to:

               key=value
               _key.source=[etcd]http://127.0.0.1:4001
               _key.createdIndex=12
               _key.modifiedIndex=34
               _key.ttl=300
               _key.expiration=...

      Parameters:
        `key` - the requested key
      Returns:
        the mapped result, including meta-entries.

    - #### set

          public Map<String,String> set(String key,
                               String value)

      Creates/updates an entry in etcd without any ttl set.
      Parameters:
        `key` - the property key, not null
        `value` - the value to be set
      Returns:
        the result map as described above.
      See Also:
        `set(String, String, Integer)`

    - #### set

          public Map<String,String> set(String key,
                               String value,
                               Integer ttlSeconds)

      Creates/updates an entry in etcd. The response as follows:

               {
           "action": "set",
           "node": {
           "createdIndex": 3,
           "key": "/message",
           "modifiedIndex": 3,
           "value": "Hello etcd"
           },
           "prevNode": {
           "createdIndex": 2,
           "key": "/message",
           "value": "Hello world",
           "modifiedIndex": 2
           }
           }

      is mapped to:

               key=value
               _key.source=[etcd]http://127.0.0.1:4001
               _key.createdIndex=12
               _key.modifiedIndex=34
               _key.ttl=300
               _key.expiry=...
                // optional
               _key.prevNode.createdIndex=12
               _key.prevNode.modifiedIndex=34
               _key.prevNode.ttl=300
               _key.prevNode.expiration=...

      Parameters:
        `key` - the property key, not null
        `value` - the value to be set
        `ttlSeconds` - the ttl in seconds (optional)
      Returns:
        the result map as described above.

    - #### delete

          public Map<String,String> delete(String key)

      Deletes a given key. The response is as follows:

               _key.source=[etcd]http://127.0.0.1:4001
               _key.createdIndex=12
               _key.modifiedIndex=34
               _key.ttl=300
               _key.expiry=...
                // optional
               _key.prevNode.createdIndex=12
               _key.prevNode.modifiedIndex=34
               _key.prevNode.ttl=300
               _key.prevNode.expiration=...
               _key.prevNode.value=...

      Parameters:
        `key` - the key to be deleted.
      Returns:
        the response mpas as described above.

    - #### getProperties

          public Map<String,String> getProperties(String directory)

      Get all properties for the given directory key recursively.
      Parameters:
        `directory` - the directory entry
      Returns:
        the properties and its metadata
      See Also:
        `getProperties(String, boolean)`

    - #### getProperties

          public Map<String,String> getProperties(String directory,
                                         boolean recursive)

      Access all properties. The response of:

           {
           "action": "get",
           "node": {
           "key": "/",
           "dir": true,
           "nodes": [
           {
           "key": "/foo_dir",
           "dir": true,
           "modifiedIndex": 2,
           "createdIndex": 2
           },
           {
           "key": "/foo",
           "value": "two",
           "modifiedIndex": 1,
           "createdIndex": 1
           }
           ]
           }
           }

      is mapped to a regular Tamaya properties map as follows:

              key1=myvalue
               _key1.source=[etcd]http://127.0.0.1:4001
               _key1.createdIndex=12
               _key1.modifiedIndex=34
               _key1.ttl=300
               _key1.expiration=...

                key2=myvaluexxx
               _key2.source=[etcd]http://127.0.0.1:4001
               _key2.createdIndex=12

                key3=val3
               _key3.source=[etcd]http://127.0.0.1:4001
               _key3.createdIndex=12
               _key3.modifiedIndex=2

      Parameters:
        `directory` - remote directory to query.
        `recursive` - allows to set if querying is performed recursively
      Returns:
        all properties read from the remote server.

    - #### getUrl

          public String getUrl()

      Access the server root URL used by this accessor.
      Returns:
        the server root URL.

Copyright © 2014–2016 Apache Software Foundation. All rights reserved.