VintageNet.PropertyTable (vintage_net v0.11.3) View Source

PropertyTables are in-memory key-value stores

Users can subscribe to keys or groups of keys to be notified of changes.

Keys are hierarchically layed out with each key being represented as a list for the path to the key. For example, to get the current state of the network interface eth0, you would get the value of the key, ["net", "ethernet", "eth0"].

Values can be any Elixir data structure except for nil. nil is used to identify non-existent keys. Therefore, setting a property to nil deletes the property.

Users can get and listen for changes in multiple keys by specifying prefix paths. For example, if you wants to get every network property, run:

PropertyTable.get_by_prefix(table, ["net"])

Likewise, you can subscribe to changes in the network status by running:

PropertyTable.subscribe(table, ["net"])

Properties can include metadata. PropertyTable only specifies that metadata is a map.

Link to this section Summary

Types

Properties

A table_id identifies a group of properties

Functions

Returns a specification to start a property_table under a supervisor. See Supervisor.

Clear out a property

Clear out all properties under a prefix

Fetch a property with the time that it was set

Get the current value of a property

Get a list of all properties matching the specified prefix

Get a list of all properties matching the specified prefix

Update a property and notify listeners

Subscribe to receive events

Stop subscribing to a property

Link to this section Types

Specs

metadata() :: map()

Specs

options() :: [name: table_id(), properties: [property_value()]]

Specs

property() :: [String.t()]

Properties

Specs

property_value() :: {property(), value()}
Link to this type

property_with_wildcards()

View Source

Specs

property_with_wildcards() :: [String.t() | :_]

Specs

table_id() :: atom()

A table_id identifies a group of properties

Specs

value() :: any()

Link to this section Functions

Returns a specification to start a property_table under a supervisor. See Supervisor.

Clear out a property

Link to this function

clear_prefix(table, name)

View Source

Clear out all properties under a prefix

Link to this function

fetch_with_timestamp(table, name)

View Source

Specs

fetch_with_timestamp(table_id(), property()) ::
  {:ok, value(), integer()} | :error

Fetch a property with the time that it was set

Timestamps come from System.monotonic_time()

Link to this function

get(table, name, default \\ nil)

View Source

Specs

get(table_id(), property(), value()) :: value()

Get the current value of a property

Link to this function

get_by_prefix(table, prefix)

View Source

Specs

get_by_prefix(table_id(), property()) :: [{property(), value()}]

Get a list of all properties matching the specified prefix

Specs

Get a list of all properties matching the specified prefix

Link to this function

put(table, name, value, metadata \\ %{})

View Source

Specs

put(table_id(), property(), value(), metadata()) :: :ok

Update a property and notify listeners

Specs

start_link(options()) :: {:ok, pid()} | {:error, term()}

Specs

subscribe(table_id(), property_with_wildcards()) :: :ok

Subscribe to receive events

Link to this function

unsubscribe(table, name)

View Source

Specs

unsubscribe(table_id(), property_with_wildcards()) :: :ok

Stop subscribing to a property