Phoenix.Tracker.State

Phoenix.Tracker.State

Provides an ORSWOT CRDT.

Summary

Types

clock()
cloud()
context()
delta()
ets_id()
key()
meta()
name()
pid_lookup()
t()
tag()
topic()
value()
values()

Functions

clocks(state)

Returns the causal context for the set

compact(state)

Compacts a sets causal history

delta_size(state)

Returns the dize of the delta

extract(state)

Extracts the set's elements from ets into a mergeable list

get_by_pid(state, pid)

Returns all elements for the pid

get_by_pid(state, pid, topic, key)

Returns the element matching the pid, topic, and key

get_by_topic(state, topic)

Returns a list of elements for the topic who belong to an online replica

has_delta?(state)

Checks if set has a non-empty delta

join(state, pid, topic, key, meta \\ %{})

Adds a new element to the set

leave(state, pid)

Removes all elements from the set for the given pid

leave(state, pid, topic, key)

Removes an element from the set

merge(local, remote)

Merges two sets, or a delta into a set

merge_deltas(local, remote)
new(replica)

Creates a new set for the replica

online_list(state)

Returns a list of elements in the set belonging to an online replica

remove_down_replicas(state, replica)

Removes all elements for replicas that are permanently gone

replica_down(state, replica)

Marks a replica as down in the set and returns left users

replica_up(state, replica)

Marks a replica as up in the set and returns rejoined users

reset_delta(state)

Resets the set's delta

Types

clock :: pos_integer
context :: %{optional(name) => clock}
delta :: %Phoenix.Tracker.State{cloud: term, context: term, delta: term, mode: :delta, pids: term, range: term, replica: term, replicas: term, values: term}
ets_id :: pos_integer
key :: term
meta :: Map.t
name :: term
pid_lookup :: {pid, topic, key}
t :: %Phoenix.Tracker.State{cloud: cloud, context: context, delta: :unset | delta, mode: :unset | :delta | :normal, pids: ets_id, range: {context, context}, replica: name, replicas: %{optional(name) => :up | :down}, values: values}
tag :: {name, clock}
value :: {{topic, pid, key}, meta, tag}
values ::
  ets_id |
  :extracted |
  %{optional(tag) => {pid, topic, key, meta}}

Functions

clocks(state)

Specs

clocks(t) :: {name, context}

Returns the causal context for the set.

compact(state)

Specs

compact(t) :: t

Compacts a sets causal history.

Called as needed and after merges.

delta_size(state)

Specs

delta_size(delta) :: pos_integer

Returns the dize of the delta.

extract(state)

Specs

extract(t) :: {t, values}

Extracts the set's elements from ets into a mergeable list.

Used when merging two sets.

get_by_pid(state, pid)

Specs

get_by_pid(t, pid) :: [value]

Returns all elements for the pid.

get_by_pid(state, pid, topic, key)

Specs

get_by_pid(t, pid, topic, key) :: value | nil

Returns the element matching the pid, topic, and key.

get_by_topic(state, topic)

Specs

get_by_topic(t, topic) :: [value]

Returns a list of elements for the topic who belong to an online replica.

has_delta?(state)

Specs

has_delta?(t) :: boolean

Checks if set has a non-empty delta.

join(state, pid, topic, key, meta \\ %{})

Specs

join(t, pid, topic, key, meta) :: t

Adds a new element to the set.

leave(state, pid)

Specs

leave(t, pid) :: t

Removes all elements from the set for the given pid.

leave(state, pid, topic, key)

Specs

leave(t, pid, topic, key) :: t

Removes an element from the set.

merge(local, remote)

Specs

merge(local :: t, {remote :: t, values} | delta) :: {new_local :: t, joins :: [value], leaves :: [value]}

Merges two sets, or a delta into a set.

Returns a 3-tuple of the updated set, and the joined and left elements.

Examples

iex> {s1, joined, left} =
     Phoenix.Tracker.State.merge(s1, Phoenix.Tracker.State.extract(s2))

{%Phoenix.Tracker.State{}, [...], [...]}

merge_deltas(local, remote)

new(replica)

Specs

new(name) :: t

Creates a new set for the replica.

Examples

iex> Phoenix.Tracker.State.new(:replica1)
%Phoenix.Tracker.State{...}

online_list(state)

Specs

online_list(t) :: [value]

Returns a list of elements in the set belonging to an online replica.

remove_down_replicas(state, replica)

Specs

remove_down_replicas(t, name) :: t

Removes all elements for replicas that are permanently gone.

replica_down(state, replica)

Specs

replica_down(t, name) :: {t, joins :: [], leaves :: [values]}

Marks a replica as down in the set and returns left users.

replica_up(state, replica)

Specs

replica_up(t, name) :: {t, joins :: [values], leaves :: []}

Marks a replica as up in the set and returns rejoined users.

reset_delta(state)

Specs

reset_delta(t) :: t

Resets the set's delta.

© 2014 Chris McCord
Licensed under the MIT License.
https://hexdocs.pm/phoenix_pubsub/Phoenix.Tracker.State.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部