Beethoven.CoreServer behaviour (Beethoven v0.2.7)

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

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.

Callbacks

Callback needed for downlevel services to streamline receiving node down updates.

Functions

Adds a node to Mnesia cluster

Tell the local CoreServer that we want to be alerted to changes to cluster node state.

Returns a specification to start this module under a supervisor.

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

Gets mode from the CoreServer.

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.

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.

Callbacks

node_update(nodeName, status)

@callback node_update(nodeName :: node(), status :: nodeStatus()) :: :ok

Callback needed for downlevel services to streamline receiving node down updates.

Required if you follow core server for cluster updates via alert_me/1

Functions

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.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

entry_point(mode)

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

get_mode()

@spec get_mode() :: serverStatus()

Gets mode from the CoreServer.

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.

node_update(nodeName, status)

Callback implementation for Beethoven.CoreServer.node_update/2.

start_link(init_args)

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

Supervisor Entry point.