Pixie.Backend behaviour

Used to implement the persistence backend for Pixie.

Source

Summary

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

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

Functions

client_subscribed?(client_id, channel_name)

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

Source
create_client()

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

Source
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.

Source
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).

Source
destroy_client(client_id, reason)
Source
generate_namespace()

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

Source
generate_namespace(length)
Source
get_client(client_id)

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

Source
ping_client(client_id)

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

Source
publish(messages)

Publishes a collection of messages to all their receiving clients.

Source
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.

Source
release_namespace(namespace)

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

Source
start_link(name, options)

Called by the Pixie supervisor to start the selected backend.

Source
subscribe(client_id, channel_name)

Subscribe the specified client to the specified channel.

Source
subscribed_to(client_id)

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

Source
subscribers_of(channel_name)

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

Source
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.

Source

Callbacks

start_link/1

Specs:

  • start_link(options :: any) :: {atom, pid}

Used to start your Backend's process.

Source
generate_namespace/1

Specs:

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

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

Source
release_namespace/1

Specs:

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

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

Source
create_client/0

Specs:

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

Create a new Pixie.Client process.

Source
get_client/1

Specs:

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

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

Source
destroy_client/2

Specs:

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

Destroy a client.

Source
subscribe/2

Specs:

Subscribe a client to a channel

Source
unsubscribe/2

Specs:

Unsubscribe a client from a channel

Source
subscribers_of/1

Specs:

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

Retrieve the unique subscribers of channels matching the channel pattern.

Source
subscribed_to/1

Specs:

Retrieve the channels that the client is subscribed to.

Source
client_subscribed?/2

Specs:

Check whether the client is subscribed to the mentioned channel.

Source
queue_for/2

Specs:

  • queue_for(client_id :: String.t, messages :: [%{}]) :: atom

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

Source
dequeue_for/1

Specs:

  • dequeue_for(client_id :: String.t) :: [%{}]

Dequeue any stored messages for a given client.

Source