sbroker_meter behaviour (sbroker v1.1.2)
Behaviour for implementing meters for sbroker and sregulator.
sbroker_meter behaviour. The first callback is init/2, which starts the meter: -callback init(Time :: integer(), Args :: any()) ->
{State :: any(), UpdateTime :: integer() | infinity}.Time is the time, in native time units, of the meter at creation. Some other callbacks will receive the current time of the meter as the second last argument. It is monotically increasing, so subsequent calls will have the same or a greater time.
Args is the arguments for the meter. It can be any term.
State is the state of the meter and used in the next call.
UpdateTime represents the next time a meter wishes to call handle_update/4 to update itself. If a message is not recevued the update should occur at or after UpdateTime. The time must be greater than or equal to Time. If a meter does not require an update then UpdateTime should be infinity.
handle_update/5: -callback handle_update(QueueDelay :: non_neg_integer(),
ProcessDelay :: non_neg_integer(),
RelativeTime :: integer(), Time :: integer(),
State :: any()) ->
{NState :: any(), UpdateTime :: integer() | infinity}.QueueDelay is the approximate time a message spends in the message queue of the process. ProcessDelay is the average time spent processing a message since the last update. RelativeTime is an approximation of the RelativeTime for an ask request if a match was to occur immediately. If the process has not matched a request for a significant period of time this value can grow large and become inaccurate.
The other variables are equivalent to those in init/2, with NState being the new state.
handle_info/3: -callback handle_info(Msg :: any(), Time :: integer(), State :: any()) ->
{NState :: any(), TimeoutTime :: integer() | infinity}.Msg is the message, and may be intended for another callback.
The other variables are equivalent to those in init/2, with NState being the new state.
The other variables are equivalent to those in init/3, with NState being the new state.
code_change/4: -callback code_change(OldVsn :: any(), Time :: integer(), State :: any(),
Extra :: any()) ->
{NState :: any(), TimeoutTime :: integer() | infinity}.On an upgrade OldVsn is version the state was created with and on an downgrade is the same form except {down, OldVsn}. OldVsn is defined by the vsn attribute(s) of the old version of the callback module. If no such attribute is defined, the version is the checksum of the BEAM file. Extra is from {advanced, Extra} in the update instructions.
The other variables are equivalent to those in init/3, with NState being the new state.
config_change/4: -callback config_change(Args :: any(), Time :: integer(), State :: any()) ->
{NState :: any(), TimeoutTime :: integer() | infinity}.The variables are equivalent to those in init/2, with NState being the new state.
terminate/2: -callback terminate(Reason :: sbroker_handlers:reason(), State :: any()) ->
any().Reason is stop if the meter is being shutdown, change if the meter is being replaced by another meter, {bad_return_value, Return} if a previous callback returned an invalid term or {Class, Reason, Stack} if a previous callback raised an exception.
State is the current state of the meter.
Summary
Callbacks
code_change/4
-callback code_change(OldVsn :: any(), Time :: integer(), State :: any(), Extra :: any()) ->
{NState :: any(), TimeoutTime :: integer() | infinity}.
config_change/3
-callback config_change(Args :: any(), Time :: integer(), State :: any()) ->
{NState :: any(), UpdateTime :: integer() | infinity}.
handle_info/3
-callback handle_info(Msg :: any(), Time :: integer(), State :: any()) ->
{NState :: any(), UpdateTime :: integer() | infinity}.
handle_update/5
-callback handle_update(QueueDelay :: non_neg_integer(),
ProcessDelay :: non_neg_integer(),
RelativeTime :: integer(),
Time :: integer(),
State :: any()) ->
{NState :: any(), UpdateTime :: integer() | infinity}.
init/2
-callback init(Time :: integer(), Args :: any()) -> {State :: any(), UpdateTime :: integer() | infinity}.
terminate/2
-callback terminate(Reason :: sbroker_handlers:reason(), State :: any()) -> any().