Malla.Service.Interface behaviour (malla v0.0.1-rc.1)

Copy Markdown View Source

Behaviour defining the public interface for Malla services.

Any module using Malla.Service will implement this behaviour, providing the standard API functions for starting, stopping, configuring, and querying the service readily available inserted in service module.

Sice they live at ther service module, the service ID is already known (it is the module itself) so you don't need to provide it.

You cannot override these functions, they are included here only for documentation purposes. Use the mechanism detailed in Malla.Service and Malla.Plugin to use Malla's plugin system.

Summary

Callbacks

Provides a standard supervisor spec to start the Service.

Gets current service configuration, or :unknown if not started,

Gets current service configurartion, or :unknown if not started.

This function is called from functions like Malla.remote/3 to call services on remote nodes.

Reconfigures the service in real time. See Malla.Service.reconfigure/2.

Starts the service. See Malla.Service.start_link/2.

Stops the service. See Malla.Service.stop/1.

Callbacks

child_spec(start_opts)

@callback child_spec(start_opts :: keyword()) :: Supervisor.child_spec()

Provides a standard supervisor spec to start the Service.

Restart will be transient so supervisor will not restart it if we stop it with stop/0. Shutdown will be infinity to allow plugins to stop.

get_config()

@callback get_config() :: keyword() | :unknown

Gets current service configuration, or :unknown if not started,

get_status()

@callback get_status() :: Malla.Service.running_status() | :unknown

Gets current service configurartion, or :unknown if not started.

malla_cb_in(fun, args, opts)

@callback malla_cb_in(fun :: atom(), args :: list(), opts :: keyword()) :: any()

This function is called from functions like Malla.remote/3 to call services on remote nodes.

Once it receives the call:

  • It sets process global leader to :user so that responses are not sent back to caller.
  • It sets current module as current service in process's dictionary.
  • It calls callback function Malla.Plugins.Base.service_cb_in/3.

reconfigure(config)

@callback reconfigure(config :: keyword()) :: :ok | {:error, term()}

Reconfigures the service in real time. See Malla.Service.reconfigure/2.

set_admin_status(status, reason)

@callback set_admin_status(
  status :: :active | :pause | :inactive,
  reason :: atom()
) :: :ok | {:error, term()}

Changes service running status. See Malla.Service.set_admin_status/3.

start_link()

@callback start_link() :: {:ok, pid()} | {:error, term()}

Starts the service. See Malla.Service.start_link/2.

start_link(start_opts)

@callback start_link(start_opts :: keyword()) :: {:ok, pid()} | {:error, term()}

Starts the service. See Malla.Service.start_link/2.

stop()

@callback stop() :: :ok | {:error, term()}

Stops the service. See Malla.Service.stop/1.