Accessor: net/KeyValueStore

net/KeyValueStore

This accessor reads or writes data to a key-value store web service whenever it receives a trigger input. A URL for the service is specified by the storeLocation parameter. A Ptolemy II model that provides such a key-value store service can be found at https://www.icyphy.org/accessors/demo/KeyValueStore/KeyValueStoreServer.xml. A demo client that uses this accessor is provided at https://www.icyphy.org/accessors/demo/KeyValueStore/KeyValueStoreClient.xml.

The key and the value are both text items provided as inputs. If remove is true and the key is non-empty, then upon firing, this actor will remove the specified key from the store, producing on its output the previous value (if any). If remove is false, then this actor will either set or retrieve a value in the key-value store, depending on whether the value input is non-empty. If the value is non-empty, then this actor sets the value for the specified key. If it is empty, then this actor retrieves the value for the specified key. If no key is given, then this actor retrieves an array of all the keys in the key-value store.

If an error occurs accessing the key-value store (e.g., no store is found at the specified URL, or no value is found with the specified key), then an exception is thrown.

This accessor assumes that the protocol implemented at that location matches the specification below for the default location:

  • To store a value with key MY_ID and value MY_VALUE, use

    http://localhost:8077/keyvalue/set?id=MY_ID&value=MY_VALUE

  • To retrieve the value, use

    http://localhost:8077/keyvalue/get?id=MY_ID

  • To remove a value, use

    http://localhost:8077/keyvalue/delete?id=MY_ID

  • To list all the keys, use

    http://localhost:8077/keyvalue/list

    The key and value are both encoded using the JavaScript encodeURIComponent() function, and on retrieval, decoded using decodeURIComponent(), and hence can include any text characters.

    Note that this accessor uses nonblocking reads to access the store, so the output is produced later when the server responds.

Version:
  • $$Id$$
Author:
  • Edward A. Lee
Source:
Inputs:
Name Type Description
storeLocation string The URL of the key-value store service.
key string The key to be updated or retrieved.
remove boolean If true, then remove the key from the store; otherwise, retrieve the value for the key.
value string The value to store in the key-value store, or empty to not store anything.
trigger The trigger input.
Outputs:
Name Type Description
result string The value retrieved from or written to the key-value store.