Module jc_psub

jc_psub 1) allows clients to subscribe to j_cache changes; 2) notifies clients of changes to j_cache items; and 3) allows clients to subscribe to, and broadcast, topic events.

Copyright © (C) 2011 - 2015, Jim Rosenblum

Behaviours: gen_server.

Authors: Jim Rosenblum.

Description

jc_psub 1) allows clients to subscribe to j_cache changes; 2) notifies clients of changes to j_cache items; and 3) allows clients to subscribe to, and broadcast, topic events.

Subscriptions are a local afair so if a node goes down, clients that were using that node's jc_psub will need to re-subscribe.

Mnesia LOCAL tables, ps_sub and ps_client, are used:

ps_sub maps a subscription to a list of listening Pids ps_client maps a unique, subscriber's pid to a reference or link.

The server subscribes to mnesia key_to_value, table changes thereby allowing it to notice cache changes, construct the corresponding subscription message and look for relevant subscribers to whom to send a message.

Data Types

key()

key() = any()

map_name()

map_name() = any()

value()

value() = any()

Function Index

client_count/0Return the number of distinct, subscribing Pids being served by the server.
load/0Return an estimate of how much load the server is under.
map_subscribe/4Adds a subscription on behalf of the process indicated by the supplied Pid.
map_unsubscribe/4Client unsubcribes from notifiction.
start_link/0Starts the jc_psub server and links the caller to it.
topic_event/2Push a topic message to the server for broadcast to its local subscribers.
topic_subscribe/3Client subscribes to notifications regarding the given Topic.
topic_unsubscribe/3Client unsubscribes to notifications regarding the given Topic.

Function Details

client_count/0

client_count() -> non_neg_integer() | {error, any()}

Return the number of distinct, subscribing Pids being served by the server. Under extreme load this function can time-out.

load/0

load() -> non_neg_integer() | {error, any()}

Return an estimate of how much load the server is under. It counts the number of subscriptions + the number of Pids that are currenlty subscribed to anything. Under extreme load this can time-out resulting in an error.

map_subscribe/4

map_subscribe(Client::pid(), Map::map_name(), Key::key() | any, Ops::write | delete | any) -> ok | {error, badarg}

Adds a subscription on behalf of the process indicated by the supplied Pid.

map_unsubscribe/4

map_unsubscribe(Client::pid(), Map::map_name(), Key::key() | any, Ops::write | delete | any) -> ok | {error, badarg}

Client unsubcribes from notifiction.

start_link/0

start_link() -> {ok, pid()} | ignore | {error, any()}

Starts the jc_psub server and links the caller to it.

topic_event/2

topic_event(Topic::atom(), Value::value()) -> ok

Push a topic message to the server for broadcast to its local subscribers. If the event is a node event, then the other jc_psubs will know about it via their monitoring of foreign jc_sup's, so there is no need to propagate the event to other nodes' jc_psub servers; else propagate it.

topic_subscribe/3

topic_subscribe(Client::pid(), Topic::atom(), Value::value() | any) -> ok | {error, badarg}

Client subscribes to notifications regarding the given Topic.

topic_unsubscribe/3

topic_unsubscribe(Client::pid(), Topic::atom(), Value::value() | any) -> ok | {error, badarg}

Client unsubscribes to notifications regarding the given Topic.


Generated by EDoc, May 24 2016, 22:38:41.