sregulator_user (sbroker v1.1.1)
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.
sbroker
application allows multiple applications, to access a sregulator
or to isolate the regulator from errors in an application.
Link to this section Summary
Functions
Call sregulator:change_config/1
on all regulators started in the sbroker
application.
Delete a regulator with name, Name
.
Restart a regulator with name, Name
.
Starts a regulator with name, Name
.
Terminate a regulator with name, Name
.
List user regulators started in the sbroker
application.
Link to this section Functions
change_config()
Specs
change_config() -> [{Name, Reason}] when Name :: sregulator:name(), Reason :: term().
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.
Name
is the sregulator:name()
of the regulator and Reason
is the reason.
delete(Name)
Specs
delete(Name) -> ok | {error, Reason} when Name :: sregulator:name(), Reason :: running | restarting | not_found.
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
.
ok
on successfully deleting the regulator, otherwise {error, Reason}
where Reason
is reason for the error.
restart(Name)
Specs
restart(Name) -> {ok, Pid} | {error, Reason} when Name :: sregulator:name(), Pid :: pid() | undefined, Reason :: term().
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.
{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(Name)
Specs
start(Name) -> {ok, Pid} | {error, Reason} when Name :: sregulator:name(), Pid :: pid() | undefined, Reason :: term().
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.
{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(Name)
Specs
terminate(Name) -> ok | {error, not_found} when Name :: sregulator:name().
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
.
ok
once the regulator is terminated, otherwise {error, not_found}
.
which_regulators()
Specs
which_regulators() -> [{Name, Pid, Type, Modules}] when Name :: sregulator:name(), Pid :: undefined | pid(), Type :: worker, Modules :: dynamic.
List user regulators started in the sbroker
application.
Name
is the sregulator:name()
of the regulator, Pid
is the pid()
or undefined
, Type
is worker
and Modules
is dynamic
.