pixie v0.3.9 Pixie.Monitor behaviour

Allows you to monitor various events within Pixie.

Internally Pixie.Monitor is implemented using GenEvent, so you’re free to bypass using the Pixie.Monitor behaviour and use your own GenEvent if the need arises.

Usage example:

defmodule MyMonitor do
  use Pixie.Monitor

  def created_channel channel_name, at do
    Logger.info "Channel #{channel_name} created at #{format at}"
  end

  def destroyed_channel channel_name, at do
    Logger.info "Channel #{channel_name} destroyed at #{format at}"
  end

  defp format timestamp do
    timestamp
      |> Date.from(:timestamp)
      |> DateFormat.format!("{UNIX}")
  end
end

Summary

Functions

Allows you to add a Pixie.Monitor or any other GenEvent handler to the event stream. Expects the name of your handler module and any args which you wish to be provided to your module’s init/1 callback

Called by the backend when a client subscribes to a channel

Called by the backend when a client unsubscribes from a channel

Called by the backend when a new channel is created. New channels are created when the first client subscribes to them

Called by the backend when a new client is created either by protocol handshake, or via Pixie.subscribe/2

Called by adapters when a message is finally delivered to a client

Called by the backend when a channel is destroyed. Channels are destroyed when the last client unsubscribes from them

Called by the backend when a client is destroyed, either by an expicit protocol disconnect or for a system generated reason, such as a timeout

Called whenever a new message is received for publication. This includes server-generated messages using Pixie.publish/2

Callbacks

Called when a client subscribes to a channel

Called when a client unsubscribes from a channel

Called when a new channel is created - this happens when a client subscribes to it for the first time

Called when a new client is created during protocol handshake

Called when a message is delivered to a client

Called when a channel is destroyed - this happens when the last client unsubscribes from it

Called when a client is destroyed - either by an explicit disconnect request from the client, or by a system generated timeout

Called when a message is received with the ID of the message

Functions

add_handler(handler, args \\ [])

Allows you to add a Pixie.Monitor or any other GenEvent handler to the event stream. Expects the name of your handler module and any args which you wish to be provided to your module’s init/1 callback.

client_subscribed(client_id, channel_name)

Called by the backend when a client subscribes to a channel.

client_unsubscribed(client_id, channel_name)

Called by the backend when a client unsubscribes from a channel.

created_channel(channel_name)

Called by the backend when a new channel is created. New channels are created when the first client subscribes to them.

created_client(client_id)

Called by the backend when a new client is created either by protocol handshake, or via Pixie.subscribe/2

delivered_message(arg1)

Called by adapters when a message is finally delivered to a client.

destroyed_channel(channel_name)

Called by the backend when a channel is destroyed. Channels are destroyed when the last client unsubscribes from them.

destroyed_client(client_id, reason \\ "Unknown reason")

Called by the backend when a client is destroyed, either by an expicit protocol disconnect or for a system generated reason, such as a timeout.

received_message(arg1)

Called whenever a new message is received for publication. This includes server-generated messages using Pixie.publish/2

start_link(handlers)

Callbacks

client_subscribed(client_id, channel_name, at)

Specs

client_subscribed(client_id :: binary, channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a client subscribes to a channel.

client_unsubscribed(client_id, channel_name, at)

Specs

client_unsubscribed(client_id :: binary, channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a client unsubscribes from a channel.

created_channel(channel_name, at)

Specs

created_channel(channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a new channel is created - this happens when a client subscribes to it for the first time.

created_client(client_id, at)

Specs

created_client(client_id :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a new client is created during protocol handshake.

delivered_message(client_id, message_id, at)

Specs

delivered_message(client_id :: binary, message_id :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a message is delivered to a client.

Some caveats:

  • This function is only called when a publish message is delivered, not when any protocol messages, such as connect or subscribe are.
  • Message IDs are only unique per client, not globally.
  • The Client ID is that of the sender, not the receiver.
  • If the message was generated on the server (ie via Pixie.publish/2 then the Client ID is likely to be nil.
  • You will likely receive a lot of delivered calls for each received call as one message published to a channel may be relayed to thousands of receivers.
destroyed_channel(channel_name, at)

Specs

destroyed_channel(channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a channel is destroyed - this happens when the last client unsubscribes from it.

destroyed_client(client_id, reason, at)

Specs

destroyed_client(client_id :: binary, reason :: binary | atom, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a client is destroyed - either by an explicit disconnect request from the client, or by a system generated timeout.

received_message(client_id, message_id, at)

Specs

received_message(client_id :: binary, message_id :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a message is received with the ID of the message.

Some caveats:

  • This function is only called when a publish message is received, not when any protocol messages, such as connect or subscribe are received.
  • Message IDs are only unique per client, not globally.
  • If the message was generated on the server (ie via Pixie.publish/2 then the Client ID is likely to be nil.