Malla.Service.Interface behaviour (malla v0.1.0)

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.

Since they live in the 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 the current service configuration, or :unknown if not started.

Gets the current running status of the service, or :unknown if not started.

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 the current service configuration, or :unknown if not started.

get_status()

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

Gets the current running status of the service, or :unknown if not started.

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.