Grains (Grains v1.7.0)
Grains describes data flow as a graph with interchangeable parts.
To accomplish that grains divides the graph (Recipe
) from the
implementation of the nodes (Grains
).
Together these parts can be used to make a Bread
which describes
how the graph translates to processes.
Each process has a symbolic short name, which is resolved
to the registered name of the process via a map (%Bread{}.process_map
).
Link to this section Summary
Functions
Combine two sets of recipes and grains.
Debug multiple asynchronous pull paths.
Debug an asynchronous data chain.
Debug multiple asynchronous data paths.
Retrieve a grain's substate.
A ghost edge.
Merges two grain maps into one.
Description of a periodic grain.
Convenient version of routes/2
.
Takes a list of tuples of the form [{pattern, grains}]
.
Define a pattern which messages must match in order to be pushed to the successor grains. Every message gets tested against the pattern before it is pushed to the successors.
Link to this section Functions
combine(arg1, arg2)
Combine two sets of recipes and grains.
concat_name(bread, grain)
Specs
concat_name(Grains.Bread.t(), atom()) :: atom()
debug_pull_chain(first_grain, last_grain, message)
Debug multiple asynchronous pull paths.
This function floods pulls upwards from first_grain
towards last_grain
.
The function returns {:ok, number_of_paths}
to indicate how often message
should be received
by the caller of this function.
debug_reply_chain(reply_chain, message)
Debug an asynchronous data chain.
The function expects a list of grains. The grain currently handling the message
checks if its name matches the first element of the list. If so, it pops that element
and attempts to send the message to the next grain in the list. If only one element in
the list remains, and that element matches the name of the current grain handling the list,
this grain replies to the sender with message
.
debug_reply_chain(first_grain, last_grain, message)
Debug multiple asynchronous data paths.
This function floods message
along all paths between first_grain
and last_grain
. It is
a generalization of debug_reply_chain/2
, which does not require specifying the paths explicitly.
The function returns {:ok, number_of_paths}
to indicate how often message
should be received
by the caller of this function.
get_name(supervisor, short_name)
Specs
get_name(Grains.Supervisor.t(), atom()) :: atom()
get_original_recipe!(supervisor)
get_substate(bread_id)
Specs
Retrieve a grain's substate.
This is similar to :sys.get_state/1
. Note that this function should usually
not be used, but it can be useful for debugging or testing.
Errors
The function exits the caller on error. For example, if no bread with the supplied
id can be found, this results in a no_proc
exit.
ghost(grain, description \\ nil)
A ghost edge.
A ghost edge is an edge from one grain through another which is not usable by
Grains itself, but which may indicate communication between the two nodes
using standard tools such as GenServer.call/2
.
make_bread_name(recipe, bread_id)
Specs
make_bread_name(Grains.Recipe.t(), atom()) :: atom()
make_name(recipe, bread_id, short_name)
Specs
make_name(Grains.Recipe.t(), atom(), atom()) :: atom()
merge(grains1, grains2)
Merges two grain maps into one.
The function works the same as Map.merge/2
: all grains in the second
argument are added to the first, overriding any existing one.
merge_recipes(name, a, b)
new(map)
new_recipe(name, new)
See Grains.Recipe.new/2
.
periodic(grain, period, args \\ %{with_timestamps: false})
Description of a periodic grain.
Convenient version of routes/2
.
Takes a list of tuples of the form [{pattern, grains}]
.
Define a pattern which messages must match in order to be pushed to the successor grains. Every message gets tested against the pattern before it is pushed to the successors.