vintage_net v0.7.7 VintageNet.PropertyTable 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

Link to this type

metadata()

View Source
metadata() :: map()
Link to this type

property()

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

Properties

Link to this type

property_with_wildcards()

View Source
property_with_wildcards() :: [String.t() | :_]
Link to this type

table_id()

View Source
table_id() :: atom()

A table_id identifies a group of properties

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
fetch_with_timestamp(table_id(), property()) ::
  {:ok, value(), integer()} | :error

Fetch a property with the time that it was set

Timestamps come from :erlang.monotonic_time()

Link to this function

get(table, name, default \\ nil)

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

Get the current value of a property

Link to this function

get_by_prefix(table, prefix)

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

Get a list of all properties matching the specified prefix

Get a list of all properties matching the specified prefix

Link to this function

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

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

Update a property and notify listeners

Link to this function

start_link(options)

View Source
start_link([{:name, table_id()}]) :: {:ok, pid()} | {:error, term()}
Link to this function

subscribe(table, name)

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

Subscribe to receive events

Link to this function

unsubscribe(table, name)

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

Stop subscribing to a property