View Source ZenMonitor.Local (ZenMonitor v2.0.1)

ZenMonitor.Local

Most of the actual logic of monitoring and fan-out is handled by ZenMonitor.Local.Connector, see that module for more information.

ZenMonitor.Local is responsible for monitoring the subscribing local processes and cleaning up monitors if they crash.

Link to this section Summary

Types

Effective compatibility of a remote node

Represents a future down dispatch for a given pid to be delivered by ZenMonitor.Local.Dispatcher

Functions

Synchronously checks the length of the ZenMonitor.Local's internal batch

Check the compatiblity of the remote node that owns the provided destination

Stop monitoring a process by monitor reference

Asynchronously enqueue a list of down dispatches for delivery by the Dispatcher

Handles batch length checks

Handles enqueuing messages for eventual dispatch

Handle a local subscriber going down

Gets the hibernation threshold from the Application Environment

Puts the hibernation threshold into the Application Environment

Callback implementation for GenStage.init/1.

Begin monitoring the given process

Link to this section Types

Specs

compatibility() :: :compatible | :incompatible

Effective compatibility of a remote node

Specs

down_dispatch() ::
  {pid(), {:DOWN, reference(), :process, pid(), {:zen_monitor, any()}}}

Represents a future down dispatch for a given pid to be delivered by ZenMonitor.Local.Dispatcher

Link to this section Functions

Specs

batch_length() :: integer()

Synchronously checks the length of the ZenMonitor.Local's internal batch

Specs

compatibility(target :: ZenMonitor.destination()) :: compatibility()

Check the compatiblity of the remote node that owns the provided destination

This is a simple convenience function that looksup the node for the destination and then calls ZenMonitor.Local.compatiblity_for_node/1

Link to this function

compatibility_for_node(remote)

View Source

See ZenMonitor.Local.Connector.compatibility/1.

Link to this function

demonitor(ref, options \\ [])

View Source

Specs

demonitor(ref :: reference(), options :: [:flush]) :: true

Stop monitoring a process by monitor reference

Has the same semantics as Process.demonitor/2 (although you can pass the :info option, it has no effect and is not honored, :flush is honored) To demonitor a process you should pass in the reference returned from ZenMonitor.Local.monitor/1 for the given process

Specs

enqueue(messages :: [down_dispatch()]) :: :ok

Asynchronously enqueue a list of down dispatches for delivery by the Dispatcher

If called with the empty list, cast will be suppressed.

Link to this function

handle_call(atom, from, state)

View Source

Handles batch length checks

Returns the current length of the batch

Handles enqueuing messages for eventual dispatch

ZenMonitor.Local.Connector is responsible for generating down dispatches and enqueuing them with ZenMonitor.Local. ZenMonitor.Local takes these messages and places them into the batch queue to be delivered to ZenMonitor.Local.Dispatcher as demanded.

Link to this function

handle_demand(demand, state)

View Source

Handles demand from ZenMonitor.Local.Dispatcher

ZenMonitor.Local maintains a queue of pending messages to be sent to local processes, the actual dispatch of which are throttled by ZenMonitor.Local.Dispatcher. When ZenMonitor.Local.Dispatcher requests more messages to dispatch, this handler will collect up to the requested amount from the batch queue to satisfy the demand.

Handle a local subscriber going down

When a process establishes a remote monitor, ZenMonitor.Local establishes a reciprocal monitor, see monitor/1 and handle_cast({:monitor_subscriber, ...}) for more information.

If the subscriber crashes, all of the ETS records maintained by ZenMonitor.Local and the various ZenMonitor.Local.Connectors is no longer needed and will be cleaned up by this handler.

Specs

hibernation_threshold() :: integer()

Gets the hibernation threshold from the Application Environment

Every time the demand empties the queue a counter is incremented. When this counter exceeds the hibernation threshold the ZenMonitor.Local process will be sent into hibernation. See ZenMonitor.Local's @hibernation_threshold for the default value

This can be controlled at boot and runtime with the {:zen_monitor, :hibernation_threshold} setting, see ZenMonitor.Local.hibernation_threshold/1 for runtime convenience functionality.

Link to this function

hibernation_threshold(value)

View Source

Specs

hibernation_threshold(value :: integer()) :: :ok

Puts the hibernation threshold into the Application Environment

This is a simple convenience function for overwriting the {:zen_monitor, :hibernation_threshold} setting at runtime.

Callback implementation for GenStage.init/1.

Specs

monitor(target :: ZenMonitor.destination()) :: reference()

Begin monitoring the given process

Has the same semantics as Process.monitor/1, DOWN messages will be delivered at a pace controlled by the :zen_monitor, :demand_interval and :zen_monitor, :demand_amount environment variables