Module sregulator_user

This module provides helpers for managing sregulator processes that are automatically started in the sbroker supervision tree.

Behaviours: sregulator.

Description

This module provides helpers for managing sregulator processes that are automatically started in the sbroker supervision tree.

sregulator processes can be automatically started when the sbroker application starts by setting the sbroker application env regulators. It is a list of regulator names and specifications, of the form:
  [{Name :: sregulator:name(),
    Spec :: {QueueSpec :: sregulator:handler_spec(),
             ValveSpec :: sregulator:handler_spec(),
             [MeterSpec :: sregulator:handler_spec()]}}]

Name is the name of the regulator and each regulator will be registered using its name, e.g. {local, my_regulator}. Spec is the specification for the sregulator, which is equivalent to returning {ok, Spec} from the init/1 callback: QueueSpec is the queue spec, ValveSpec is the valve spec and MeterSpec is a meter spec.

Starting regulators in the sbroker application allows multiple applications, to access a sregulator or to isolate the regulator from errors in an application.

Function Index

change_config/0Call sregulator:change_config/1 on all regulators started in the sbroker application.
delete/1Delete a regulator with name, Name.
restart/1Restart a regulator with name, Name.
start/1Starts a regulator with name, Name.
terminate/1Terminate a regulator with name, Name.
which_regulators/0List user regulators started in the sbroker application.

Function Details

change_config/0

change_config() -> [{Name, Reason}]

Call sregulator:change_config/1 on all regulators started in the sbroker application.

This function can be used to reconfigure all regulators that are already started after the sbroker application env regulators is changed.

Returns a list of failed changes, where Name is the sregulator:name() of the regulator and Reason is the reason.

delete/1

delete(Name) -> ok | {error, Reason}

Delete a regulator with name, Name.

The regulator is deleted in the sbroker application's supervision tree. Regulators are automatically started when the sbroker is started, and might be restarted if the entry remains in the sbroker application env regulators, so this function should only be required to delete a regulator after it has been removed from regulators.

Returns ok on successfully deleting the regulator, otherwise {error, Reason} where Reason is reason for the error.

restart/1

restart(Name) -> {ok, Pid} | {error, Reason}

Restart a regulator with name, Name.

The regulator is restarted in the sbroker application's supervision tree using configuration from the sbroker application env regulators. Regulators are automatically started when the sbroker is started so this function should only be required if a regulator is terminated.

Returns {ok, Pid} on starting the regulator, where Pid is the pid() of the regulator, {ok, undefined} if a configuration for Name does not exist in regulators or {error, Reason} if the regulator fails to start with reason Reason.

start/1

start(Name) -> {ok, Pid} | {error, Reason}

Starts a regulator with name, Name.

The regulator is started in the sbroker application's supervision tree using configuration from the sbroker application env regulators. Regulators are automatically started when the sbroker application is started so this function should only be required if a regulator is added to the configuration.

Returns {ok, Pid} on starting the regulator, where Pid is the pid() of the regulator, {ok, undefined} if a configuration for Name does not exist in regulators or {error, Reason} if the regulator fails to start with reason Reason.

terminate/1

terminate(Name) -> ok | {error, not_found}

Terminate a regulator with name, Name.

The regulator is terminated in the sbroker application's supervision tree. Regulators are automatically started when the sbroker is started, and might be restarted if the entry remains in the sbroker application env regulators, so this function should only be required to terminate a regulator after it has been removed from regulators.

Returns ok once the regulator is terminated, otherwise {error, not_found}.

which_regulators/0

which_regulators() -> [{Name, Pid, Type, Modules}]

List user regulators started in the sbroker application.

Returns a list of regulators where Name is the sregulator:name() of the regulator, Pid is the pid() or undefined, Type is worker and Modules is dynamic.


Generated by EDoc