Beethoven.CoreServer (Beethoven v0.3.9)

Core Service for Beethoven. Watches other nodes within the cluster and cascade updates across the beethoven PIDs as needed.


External API calls

These are calls that can be made from external servers

  • alert_me/1 -> Alerts the caller on cluster node changes. (see 'Listening for cluster node changes' for more info.)
  • new_node/1 -> Adds node to CoreServer state mnesia table. (Should be called by the Listener server)
  • get_mode/0 -> Returns the mode of the CoreServer. (:standalone | :clustered)


Listening for cluster node changes

If you invoke this module via use, it will import a specialized version of alert_me/1 called alert_me/0. The only major difference is that the name of the module is input into the first parameter of alert_me/1.

Example

defmodule TestMod do
  use Elixir.Beethoven.CoreServer

  def fun() do
    :ok = alert_me()
  end

end

Using alert_me/1 from a local client, you can tell the CoreServer to call you back when there is a change to a cluster node. Ignores changes to itself, only delivers updates of other nodes.

To use this, the caller must implement the CoreServer behavior and callback node_update/2. Once a change occurs, the CoreServer will call the callback function for the following module/process. node_update/2 should contain the logic needed when a node changes state.

Summary

Types

Possible status(s) for nodes within Beethoven.

Possible statuses for CoreServer

Single tracker event from the Mnesia table

A single row in the CoreServer tracker.

Functions

Imports the alert_me/0 function into the module with special customizations for the declaring module.

Adds a node to Mnesia cluster

Tell the local CoreServer that we want to be alerted to changes to cluster node state. Update will be sent in the form of a cast.

Returns a specification to start this module under a supervisor.

Similar to :mnesia.dirty_select/2 but only needs the match spec as an argument. The table name of the DistrServer Elixir.Beethoven.CoreServer's mnesia table is input automatically as the 1st arity.

Callback for entry when we are in :standalone or :clustered mode

Fetches data from the DistrServer Elixir.Beethoven.CoreServer's mnesia table. Uses a record key to query the data. Will return all matching records.

Fetches all records from the DistrServer Elixir.Beethoven.CoreServer's mnesia table.

Gets mode from the CoreServer.

Returns the name of the DistrServer Elixir.Beethoven.CoreServer's mnesia table.

Callback to handle casts for services that need updates on node state.

Add a node to the Cluster Node tracker. If node is already tracked, it will be marked as :online.

Supervisor Entry point.

Subscribes to the table mapped to the DistrServer Elixir.Beethoven.CoreServer's mnesia table.

Checks if the DistrServer Elixir.Beethoven.CoreServer's mnesia table exists.

Holds the thread until the DistrServer Elixir.Beethoven.CoreServer's mnesia table becomes available, or timeout occurs. Defaults to 1_000 milliseconds for timeouts and 15 milliseconds for checking intervals.

Types

nodeStatus()

@type nodeStatus() :: :online | :offline

Possible status(s) for nodes within Beethoven.

Options

  • :online
  • :offline

serverStatus()

@type serverStatus() :: :standalone | :clustered

Possible statuses for CoreServer

trackerEvent()

@type trackerEvent() ::
  {opType :: :write | :delete, mod :: module(), new_row :: trackerRow(),
   old_rows :: [trackerRow()], pid_struct :: any()}

Single tracker event from the Mnesia table

trackerRow()

@type trackerRow() ::
  {mod :: module(), nodeName :: node(), status :: nodeStatus(),
   lastChange :: DateTime.t()}

A single row in the CoreServer tracker.

Functions

__using__(opt)

(macro)

Imports the alert_me/0 function into the module with special customizations for the declaring module.

add_node_to_mnesia(nodeName)

@spec add_node_to_mnesia(node()) :: :ok

Adds a node to Mnesia cluster

alert_me(module_name)

@spec alert_me(module()) :: :ok

Tell the local CoreServer that we want to be alerted to changes to cluster node state. Update will be sent in the form of a cast.

Example

{:node_update, {nodeName, status}}

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

dirty_select(matchSpec)

@spec dirty_select(:ets.match_spec()) :: [tuple()] | list()

Similar to :mnesia.dirty_select/2 but only needs the match spec as an argument. The table name of the DistrServer Elixir.Beethoven.CoreServer's mnesia table is input automatically as the 1st arity.

entry_point(mode)

Callback for entry when we are in :standalone or :clustered mode

fetch(key)

@spec fetch(any()) :: [tuple()] | list()

Fetches data from the DistrServer Elixir.Beethoven.CoreServer's mnesia table. Uses a record key to query the data. Will return all matching records.

fetch_all()

@spec fetch_all() :: [tuple()] | list()

Fetches all records from the DistrServer Elixir.Beethoven.CoreServer's mnesia table.

get_mode()

@spec get_mode() :: serverStatus()

Gets mode from the CoreServer.

get_table_name()

@spec get_table_name() :: module() | atom()

Returns the name of the DistrServer Elixir.Beethoven.CoreServer's mnesia table.

handle_cast(msg, state)

Callback to handle casts for services that need updates on node state.

new_node(nodeName)

@spec new_node(node()) :: :ok

Add a node to the Cluster Node tracker. If node is already tracked, it will be marked as :online.

start_link(init_args)

@spec start_link(serverStatus()) :: GenServer.on_start()

Supervisor Entry point.

subscribe(type \\ :simple)

@spec subscribe(:simple | :detailed) :: :ok

Subscribes to the table mapped to the DistrServer Elixir.Beethoven.CoreServer's mnesia table.

Matches based on subscription

:simple

{:mnesia_table_event, {:atom, record(), _op_data}}

:detailed

{:mnesia_table_event, {:atom, module() | :atom(), record(), [] | [record()], _op_data}}

table_exists?()

@spec table_exists?() :: boolean()

Checks if the DistrServer Elixir.Beethoven.CoreServer's mnesia table exists.

until_exists(int \\ 15, timeout \\ 1000, acc \\ 0)

Holds the thread until the DistrServer Elixir.Beethoven.CoreServer's mnesia table becomes available, or timeout occurs. Defaults to 1_000 milliseconds for timeouts and 15 milliseconds for checking intervals.