View Source blockade (blockade v0.2.1)

This module defines the public API for the blockade application.

Link to this section Summary

Types

Dispatch options.
Event payload which can be any term.
Boolean indicating whether to discard events or not in case the priority of the event is lower than the priority of the event manager.
The name of the event.
Boolean indicating whether the priority should be synchronized within the cluster.
Boolean indicating whether to discard events or not when the priority of the event is lower than the priority of the event manager.
Priority options.
Priority level. The higher the priority the more important the event.
Queued event.
Start up options which can be passed to the start_link function.

Functions

Adds a handler to an event. The process calling the function will be added to the event group.

Child spec for the blockade event manager supervisor.

Boolean flag to enable or disable the event discarding feature.

Dispatches event asynchronously.

Dispatches event asynchronously with options.

Dispatches event synchronously.

Dispatches event synchronously with options.

Returns the list of queued events.
Returns a list of events registered under the event manager.
Returns a list of process identifiers that are subscribed to the event.
Returns the priority of the event queue.
Returns the state of the event manager.
Removes all queued events.

Remove a handler from an event.

Sets the priority of the event queue.

Sets the priority of the event queue with options.

Start a blockade event manager supervisor.

Link to this section Types

-type dispatch_opts() ::
    #{priority => priority(),
      members => local | global | external | [node()],
      discard_event => event_discard(),
      atomic_priority_set => priority(),
      local_priority_set => boolean()}.
Dispatch options.
-type event() :: atom().
Event payload which can be any term.
-type event_discard() :: boolean().
Boolean indicating whether to discard events or not in case the priority of the event is lower than the priority of the event manager.
-type event_manager() :: atom().
The name of the event.
-type event_payload() :: term().
Boolean indicating whether the priority should be synchronized within the cluster.
-type priority() :: integer().
Boolean indicating whether to discard events or not when the priority of the event is lower than the priority of the event manager.
-type priority_opts() ::
    #{reset_after => integer(),
      discard_events => event_discard(),
      local_priority_set => boolean()}.
Priority options.
-type priority_sync() :: true | false.
Priority level. The higher the priority the more important the event.
-type queued_event() :: {event(), event_payload(), dispatch_opts()}.
Queued event.
-type start_up_opts() ::
    #{name => event_manager(),
      priority => priority(),
      discard_events => event_discard(),
      priority_sync => priority_sync()}.
Start up options which can be passed to the start_link function.

Link to this section Functions

Link to this function

add_handler(EventManager, Event)

View Source
-spec add_handler(event_manager(), event()) -> ok.

Adds a handler to an event. The process calling the function will be added to the event group.

Calling this function multiple times with the same event will add the process to the event group multiple times and the process will receive the event multiple times.
-spec child_spec(map()) -> map().
Child spec for the blockade event manager supervisor.
Link to this function

discard_events(EventManager, Flag)

View Source
-spec discard_events(event_manager(), event_discard()) -> ok | {error, flag_not_boolean}.

Boolean flag to enable or disable the event discarding feature.

If the flag is set to true, the event queue will discard events that have lower priority than the event queue priority.
Link to this function

dispatch(EventManager, Event, Payload)

View Source
-spec dispatch(event_manager(), event(), event_payload()) -> ok.

Dispatches event asynchronously.

The event will be dispatched to all the processes that are subscribed to the event.

If no options are passed to the function, the event will be dispatched across the cluster.
Link to this function

dispatch(EventManager, Event, Payload, Opts)

View Source
-spec dispatch(event_manager(), event(), event_payload(), dispatch_opts()) -> ok.

Dispatches event asynchronously with options.

The event will be dispatched to all the processes that are subscribed to the event.
Link to this function

dispatch_sync(EventManager, Event, Payload)

View Source
-spec dispatch_sync(event_manager(), event(), event_payload()) ->
                 {ok, event_dispatched} | {ok, event_queued} | {ok, event_discarded}.

Dispatches event synchronously.

The function will return when all messages are sent to the subscribed processes. This does not mean that all processes have handled the event because the messages are sent asynchronously.

The event will be dispatched to all the processes that are subscribed to the event.

If no options are passed to the function, the event will be dispatched across the cluster.
Link to this function

dispatch_sync(EventManager, Event, Payload, Opts)

View Source
-spec dispatch_sync(event_manager(), event(), event_payload(), dispatch_opts()) ->
                 {ok, event_dispatched} | {ok, event_queued} | {ok, event_discarded}.

Dispatches event synchronously with options.

The function will return when all messages are sent to the subscribed processes. This does not mean that all processes have handled the event because the messages are sent asynchronously.

The event will be dispatched to all the processes that are subscribed to the event.

If no options are passed to the function, the event will be dispatched across the cluster.
Link to this function

get_event_queue(EventManager)

View Source
-spec get_event_queue(event_manager()) -> {ok, list()}.
Returns the list of queued events.
Link to this function

get_events(EventManager)

View Source
-spec get_events(event_manager()) -> {ok, [event()]}.
Returns a list of events registered under the event manager.
Link to this function

get_handlers(EventManager, Event)

View Source
-spec get_handlers(event_manager(), event()) -> {ok, [pid()]}.
Returns a list of process identifiers that are subscribed to the event.
Link to this function

get_priority(EventManager)

View Source
-spec get_priority(event_manager()) -> {ok, priority()}.
Returns the priority of the event queue.
Link to this function

local_manager_state(EventManager)

View Source
-spec local_manager_state(event_manager()) -> {ok, map()}.
Returns the state of the event manager.
Link to this function

prune_event_queue(EventManager)

View Source
-spec prune_event_queue(event_manager()) -> ok.
Removes all queued events.
Link to this function

remove_handler(EventManager, Event)

View Source
-spec remove_handler(event_manager(), event()) -> ok | not_joined.

Remove a handler from an event.

The process calling the function will be removed from the event group.
Link to this function

set_priority(EventManager, Priority)

View Source
-spec set_priority(event_manager(), priority()) -> ok | {error, priority_not_integer}.

Sets the priority of the event queue.

The priority will be propagated to all the nodes in the cluster.

Default priority is 0.
Link to this function

set_priority(EventManager, Priority, Opts)

View Source
-spec set_priority(event_manager(), priority(), priority_opts()) -> ok | {error, priority_not_integer}.

Sets the priority of the event queue with options.

The priority will be propagated to all the nodes in the cluster.

Optionally the priority can be reset after a certain number of milliseconds and events can be discarded if the priority of the event is lower than the priority of the event queue.

Default priority is 0.
-spec start_link(start_up_opts()) -> {ok, pid()} | ignore | {error, term()}.
Start a blockade event manager supervisor.