pixie v0.3.9 Pixie.Backend behaviour

Used to implement the persistence backend for Pixie.

Summary

Functions

Responds true or false depending on whether the client_id is subscribed to the given channel

Create a client. Used internally by the protocol, you probably will never call this

Dequeue any messages awaiting delivery to the specified client. This is usually only called by the protocol when a client reconnects to retrieve any messages that arrived while the client was disconnected. Use publish instead

Destroy the specified client registered to the provided client_id

Generate a unique identifier which can be used as a client_id, etc

Retrieve the pid of the client registered to the provided client_id

Ping the specified client. This is specifically used for backends which will expire clients for inactivity (ie Redis)

Publishes a collection of messages to all their receiving clients

Queue messages for delivery to the specified client. This is usually only called by the protocol when publishing messages for clients which are either in-between polls or located on another Pixie instance. Use publish instead

Release a namespace, which means it’s theoretically possible to reuse it

Called by the Pixie supervisor to start the selected backend

Subscribe the specified client to the specified channel

Returns a HashSet containing the list of channels the client is subscribed to

Returns a HashSet containing the list of client_ids subscribed to the provided channel

Unsubscribe the specified client from the specified channel

Callbacks

Check whether the client is subscribed to the mentioned channel

Create a new Pixie.Client process

Deliver messages to clients, local or otherwise

Dequeue any stored messages for a given client

Used to create a unique identifier for client ID’s, etc

Retrieve the process of a client by it’s ID

Temporarily store messages for a client if it’s transport is unconnected

Used to release a unique identifier that’s no longer in use

Used to start your Backend’s process

Subscribe a client to a channel

Retrieve the channels that the client is subscribed to

Retrieve the unique subscribers of channels matching the channel pattern

Unsubscribe a client from a channel

Functions

client_subscribed?(client_id, channel_name)

Responds true or false depending on whether the client_id is subscribed to the given channel.

create_client()

Create a client. Used internally by the protocol, you probably will never call this.

dequeue_for(client_id)

Dequeue any messages awaiting delivery to the specified client. This is usually only called by the protocol when a client reconnects to retrieve any messages that arrived while the client was disconnected. Use publish instead.

destroy_client(client_id)

Destroy the specified client registered to the provided client_id.

This function has the following side effects:

  • unsubscribes the client from all their subscribed channels.
  • destroys any channels with no subscribers left.
  • destroys any queued messages for the client.
  • releases the client_id namespace.
  • destroys the client process.
  • destroys the transport process (which has the side-effect of disconnecting the user).
destroy_client(client_id, reason)
generate_namespace()

Generate a unique identifier which can be used as a client_id, etc.

generate_namespace(length)
get_client(client_id)

Retrieve the pid of the client registered to the provided client_id.

ping_client(client_id)

Ping the specified client. This is specifically used for backends which will expire clients for inactivity (ie Redis).

publish(messages)

Publishes a collection of messages to all their receiving clients.

queue_for(client_id, messages)

Queue messages for delivery to the specified client. This is usually only called by the protocol when publishing messages for clients which are either in-between polls or located on another Pixie instance. Use publish instead.

release_namespace(namespace)

Release a namespace, which means it’s theoretically possible to reuse it.

start_link(name, options \\ [])

Called by the Pixie supervisor to start the selected backend.

subscribe(client_id, channel_name)

Subscribe the specified client to the specified channel.

subscribed_to(client_id)

Returns a HashSet containing the list of channels the client is subscribed to.

subscribers_of(channel_name)

Returns a HashSet containing the list of client_ids subscribed to the provided channel.

unsubscribe(client_id, channel_name)

Unsubscribe the specified client from the specified channel.

This function has the following side effects:

  • destroys any channels with no subscribers left.

Callbacks

client_subscribed?(client_id, channel_name)

Specs

client_subscribed?(client_id :: String.t, channel_name :: String.t) :: :atom

Check whether the client is subscribed to the mentioned channel.

create_client()

Specs

create_client :: {client_id :: String.t, pid}

Create a new Pixie.Client process.

deliver(client_id, messages)

Specs

deliver(client_id :: String.t, messages :: list) :: atom

Deliver messages to clients, local or otherwise.

dequeue_for(client_id)

Specs

dequeue_for(client_id :: String.t) :: [map]

Dequeue any stored messages for a given client.

destroy_client(client_id, reason)

Specs

destroy_client(client_id :: String.t, reason :: atom) :: atom

Destroy a client.

generate_namespace(length)

Specs

generate_namespace(length :: integer) :: String.t

Used to create a unique identifier for client ID’s, etc.

get_client(client_id)

Specs

get_client(client_id :: String.t) :: pid

Retrieve the process of a client by it’s ID.

queue_for(client_id, messages)

Specs

queue_for(client_id :: String.t, messages :: [map]) :: atom

Temporarily store messages for a client if it’s transport is unconnected.

release_namespace(namespace)

Specs

release_namespace(namespace :: String.t) :: atom

Used to release a unique identifier that’s no longer in use.

start_link(options)

Specs

start_link(options :: list) :: {atom, pid}

Used to start your Backend’s process.

subscribe(client_id, channel_name)

Specs

subscribe(client_id :: String.t, channel_name :: String.t) :: atom

Subscribe a client to a channel

subscribed_to(client_id)

Specs

subscribed_to(client_id :: String.t) :: [String.t]

Retrieve the channels that the client is subscribed to.

subscribers_of(channel_pattern)

Specs

subscribers_of(channel_pattern :: String.t) :: [pid]

Retrieve the unique subscribers of channels matching the channel pattern.

unsubscribe(client_id, channel_name)

Specs

unsubscribe(client_id :: String.t, channel_name :: String.t | [String.t]) :: atom

Unsubscribe a client from a channel