View Source ProcessHub.Service.Dispatcher (ProcessHub v0.8.0)

The dispatcher service provides API functions for dispatching events.

Summary

Functions

Sends StartChildrenRequest structs to their target coordinator processes.

Sends StopChildrenRequest structs to their target coordinator processes.

Dispatches an event to the event queue.

Dispatches an event to the event queue without waiting for it.

Propagates a request to cluster members via the synchronization strategy.

Sends a message to all the respondents who are waiting for a response.

Sends requests to the worker queues of members over the channel every request travels, so on each node they run after every request sent there before them from this node.

Returns the nodes this node recently sent a start for child_id to, and forgets them, so the same stop is not forwarded twice. A target that has since left the cluster is dropped: a stop sent there is never answered, and the child it may have started went with it.

Functions

Link to this function

children_start(hub, node_start_requests, opts \\ [])

View Source

Sends StartChildrenRequest structs to their target coordinator processes.

Each StartChildrenRequest contains all routing information needed by the remote node to process the request and send responses back. Options are those of send_requests/4.

Link to this function

children_stop(hub, node_stop_requests, opts \\ [])

View Source

Sends StopChildrenRequest structs to their target coordinator processes.

Each StopChildrenRequest contains all routing information needed by the remote node to process the request and send responses back. Options are those of send_requests/4.

Link to this function

dispatch_event(event_queue, event_id, event_data, opts \\ %{})

View Source
@spec dispatch_event(atom(), atom(), term(), %{
  optional(:discard_event) => boolean(),
  optional(:members) => :global | :local | :external | [node()]
}) :: {:ok, :event_discarded | :event_dispatched | :event_queued}

Dispatches an event to the event queue.

Link to this function

dispatch_event_async(event_queue, event_id, event_data, opts \\ %{})

View Source
@spec dispatch_event_async(atom(), atom(), term(), %{
  optional(:discard_event) => boolean(),
  optional(:members) => :global | :local | :external | [node()]
}) :: :ok

Dispatches an event to the event queue without waiting for it.

The event queue sends to every member in turn, so a peer whose connection has stopped draining holds it until the connection recovers or drops. The coordinator uses this for its own events so it never waits on such a peer. Events sent from one process keep their order, also relative to the ones it sends with dispatch_event/4.

The queue is bounded: past 10000 waiting events the sender waits for it as with dispatch_event/4, so a stalled peer slows the sender down instead of growing the queue without limit. The wait ends after the queue's own call timeout; the event stays queued.

Link to this function

propagate_event(hub, request, opts \\ [])

View Source
@spec propagate_event(ProcessHub.Hub.t(), struct(), keyword()) :: :ok

Propagates a request to cluster members via the synchronization strategy.

Options

  • :members - Target members (:global, :local, :external, or [node()]). Defaults to :global.
  • :async - see send_requests/4. Defaults to false.
Link to this function

reply_respondents(respondents, key, child_id, result, node)

View Source
@spec reply_respondents([pid()], atom(), ProcessHub.child_id(), term(), node()) :: :ok

Sends a message to all the respondents who are waiting for a response.

Link to this function

send_requests(hub, requests, members, opts \\ [])

View Source
@spec send_requests(
  ProcessHub.Hub.t(),
  [struct()],
  :global | :local | :external | [node()],
  keyword()
) :: :ok

Sends requests to the worker queues of members over the channel every request travels, so on each node they run after every request sent there before them from this node.

Options

  • :async - when true, hands the requests to the event queue without waiting (dispatch_event_async/4), for the coordinator's own paths. Defaults to false.
Link to this function

take_start_targets(hub, child_id)

View Source
@spec take_start_targets(ProcessHub.Hub.t(), ProcessHub.child_id()) :: [node()]

Returns the nodes this node recently sent a start for child_id to, and forgets them, so the same stop is not forwarded twice. A target that has since left the cluster is dropped: a stop sent there is never answered, and the child it may have started went with it.