Pixie.Backend behaviour
Used to implement the persistence backend for Pixie.
Summary
client_subscribed?(client_id, channel_name) | Responds |
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 |
destroy_client(client_id) | Destroy the specified client registered to the provided |
destroy_client(client_id, reason) | |
generate_namespace() | Generate a unique identifier which can be used as a |
generate_namespace(length) | |
get_client(client_id) | Retrieve the pid of the client registered to the provided |
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 |
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 |
subscribers_of(channel_name) | Returns a |
unsubscribe(client_id, channel_name) | Unsubscribe the specified client from the specified channel |
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
.
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).
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_id
s subscribed to the provided channel.
Unsubscribe the specified client from the specified channel.
This function has the following side effects: - destroys any channels with no subscribers left.
Callbacks
Specs:
- start_link(options :: any) :: {atom, pid}
Used to start your Backend's process.
Specs:
- generate_namespace(length :: integer) :: String.t
Used to create a unique identifier for client ID's, etc.
Specs:
- release_namespace(namespace :: String.t) :: atom
Used to release a unique identifier that's no longer in use.
Specs:
- create_client :: {client_id :: String.t, pid}
Create a new Pixie.Client
process.
Specs:
- get_client(client_id :: String.t) :: pid
Retrieve the process of a client by it's ID.
Specs:
- destroy_client(client_id :: String.t, reason :: atom) :: term
Destroy a client.
Specs:
Subscribe a client to a channel
Specs:
Unsubscribe a client from a channel
Specs:
- subscribers_of(channel_pattern :: String.t) :: [pid]
Retrieve the unique subscribers of channels matching the channel pattern.
Specs:
Retrieve the channels that the client is subscribed to.
Specs:
Check whether the client is subscribed to the mentioned channel.
Specs:
- queue_for(client_id :: String.t, messages :: [%{}]) :: atom
Temporarily store messages for a client if it's transport is unconnected.
Specs:
- dequeue_for(client_id :: String.t) :: [%{}]
Dequeue any stored messages for a given client.
Specs:
- deliver(client_id :: String.t, messages :: list) :: atom
Deliver messages to clients, local or otherwise.