Asterisk - The Open Source Telephony Project
18.5.0
|
Caching pattern for Stasis Message Bus API topics. More...
#include "asterisk/stasis.h"
Go to the source code of this file.
Functions | |
struct stasis_cache * | stasis_cp_all_cache (struct stasis_cp_all *all) |
Get the cache. More... | |
struct stasis_cp_all * | stasis_cp_all_create (const char *name, snapshot_get_id id_fn) |
Create an all instance of the cache pattern. More... | |
struct stasis_topic * | stasis_cp_all_topic (struct stasis_cp_all *all) |
Get the aggregate topic. More... | |
struct stasis_topic * | stasis_cp_all_topic_cached (struct stasis_cp_all *all) |
Get the caching topic. More... | |
int | stasis_cp_single_accept_message_type (struct stasis_cp_single *one, struct stasis_message_type *type) |
Indicate to an instance that we are interested in a message type. More... | |
struct stasis_cp_single * | stasis_cp_single_create (struct stasis_cp_all *all, const char *name) |
Create the 'one' side of the cache pattern. More... | |
int | stasis_cp_single_set_filter (struct stasis_cp_single *one, enum stasis_subscription_message_filter filter) |
Set the message type filtering level on a cache. More... | |
struct stasis_topic * | stasis_cp_single_topic (struct stasis_cp_single *one) |
Get the topic for this instance. More... | |
struct stasis_topic * | stasis_cp_single_topic_cached (struct stasis_cp_single *one) |
Get the caching topic for this instance. More... | |
void | stasis_cp_single_unsubscribe (struct stasis_cp_single *one) |
Stops caching and forwarding messages. More... | |
struct stasis_cp_single * | stasis_cp_sink_create (struct stasis_cp_all *all, const char *name) |
Create a sink in the cache pattern. More... | |
Caching pattern for Stasis Message Bus API topics.
A typical pattern for Stasis objects is to have individual objects, which have their own topic and caching topic. These individual topics feed an upstream aggregate topics, and a shared cache.
The stasis_cp_all object contains the aggregate topics and shared cache. This is built with the base name for the topics, and the identity function to identify messages in the cache.
The stasis_cp_single object contains the stasis_topic for a single instance, and the corresponding stasis_caching_topic.
Since the stasis_cp_single object has subscriptions for forwarding and caching, it must be disposed of using stasis_cp_single_unsubscribe() instead of simply ao2_cleanup().
Definition in file stasis_cache_pattern.h.
struct stasis_cache* stasis_cp_all_cache | ( | struct stasis_cp_all * | all | ) |
Get the cache.
This is the shared cache for all corresponding stasis_cp_single objects.
all | All side caching pattern object. |
NULL
if all is NULL
Definition at line 118 of file stasis_cache_pattern.c.
References stasis_cp_all::cache, and NULL.
Referenced by ast_endpoint_cache().
struct stasis_cp_all* stasis_cp_all_create | ( | const char * | name, |
snapshot_get_id | id_fn | ||
) |
Create an all instance of the cache pattern.
This object is AO2 managed, so dispose of it with ao2_cleanup().
name | Base name of the topics. |
id_fn | Identity function for the cache. |
NULL
on error. Definition at line 65 of file stasis_cache_pattern.c.
References all_dtor(), ao2_ref, ao2_t_alloc, ast_asprintf, ast_atomic_fetchadd_int(), ast_free, stasis_cp_all::cache, stasis_cp_all::forward_all_to_cached, NULL, stasis_cache_create(), stasis_forward_all(), stasis_topic_create(), stasis_cp_all::topic, and stasis_cp_all::topic_cached.
Referenced by ast_endpoint_stasis_init().
struct stasis_topic* stasis_cp_all_topic | ( | struct stasis_cp_all * | all | ) |
Get the aggregate topic.
This topic aggregates all messages published to corresponding stasis_cp_single_topic() topics.
all | All side caching pattern object. |
NULL
if all is NULL
Definition at line 101 of file stasis_cache_pattern.c.
References NULL, and stasis_cp_all::topic.
Referenced by ast_endpoint_topic_all().
struct stasis_topic* stasis_cp_all_topic_cached | ( | struct stasis_cp_all * | all | ) |
Get the caching topic.
This topic aggregates all messages from the corresponding stasis_cp_single_topic_cached() topics.
Note that one normally only subscribes to the caching topic, since data is fed to it from its upstream topic.
all | All side caching pattern object. |
NULL
if all is NULL
Definition at line 109 of file stasis_cache_pattern.c.
References NULL, and stasis_cp_all::topic_cached.
Referenced by ast_endpoint_topic_all_cached().
int stasis_cp_single_accept_message_type | ( | struct stasis_cp_single * | one, |
struct stasis_message_type * | type | ||
) |
Indicate to an instance that we are interested in a message type.
This will cause the caching topic to receive messages of the given message type. This enables internal filtering in the stasis message bus to reduce messages.
one | One side of the cache pattern. |
type | The message type we wish to receive. |
0 | on success |
-1 | failure |
Definition at line 222 of file stasis_cache_pattern.c.
References stasis_caching_accept_message_type(), and stasis_cp_single::topic_cached.
Referenced by endpoint_internal_create().
struct stasis_cp_single* stasis_cp_single_create | ( | struct stasis_cp_all * | all, |
const char * | name | ||
) |
Create the 'one' side of the cache pattern.
Create the 'one' and forward to all's topic and topic_cached.
Dispose of using stasis_cp_single_unsubscribe().
all | Corresponding all side. |
name | Base name for the topics. |
Definition at line 139 of file stasis_cache_pattern.c.
References ao2_ref, stasis_cp_single::forward_cached_to_all, stasis_cp_single::forward_topic_to_all, NULL, stasis_caching_get_topic(), stasis_cp_sink_create(), stasis_forward_all(), stasis_cp_all::topic, stasis_cp_single::topic, stasis_cp_all::topic_cached, and stasis_cp_single::topic_cached.
Referenced by endpoint_internal_create().
int stasis_cp_single_set_filter | ( | struct stasis_cp_single * | one, |
enum stasis_subscription_message_filter | filter | ||
) |
Set the message type filtering level on a cache.
This will cause the underlying subscription to filter messages according to the provided filter level. For example if selective is used then only messages matching those provided to stasis_subscription_accept_message_type will be raised to the subscription callback.
one | One side of the cache pattern. |
filter | What filter to use |
0 | on success |
-1 | failure |
Definition at line 231 of file stasis_cache_pattern.c.
References stasis_caching_set_filter(), and stasis_cp_single::topic_cached.
Referenced by endpoint_internal_create().
struct stasis_topic* stasis_cp_single_topic | ( | struct stasis_cp_single * | one | ) |
Get the topic for this instance.
This is the topic to which one would post instance-specific messages, or subscribe for single-instance, uncached messages.
one | One side of the cache pattern. |
NULL
if one is NULL
Definition at line 205 of file stasis_cache_pattern.c.
References NULL, and stasis_cp_single::topic.
Referenced by ast_endpoint_topic(), and endpoint_internal_create().
struct stasis_topic* stasis_cp_single_topic_cached | ( | struct stasis_cp_single * | one | ) |
Get the caching topic for this instance.
Note that one normally only subscribes to the caching topic, since data is fed to it from its upstream topic.
one | One side of the cache pattern. |
NULL
if one is NULL
Definition at line 213 of file stasis_cache_pattern.c.
References NULL, stasis_caching_get_topic(), and stasis_cp_single::topic_cached.
Referenced by ast_endpoint_topic_cached().
void stasis_cp_single_unsubscribe | ( | struct stasis_cp_single * | one | ) |
Stops caching and forwarding messages.
one | One side of the cache pattern. |
Definition at line 189 of file stasis_cache_pattern.c.
References ao2_cleanup, stasis_cp_single::forward_cached_to_all, stasis_cp_single::forward_topic_to_all, NULL, stasis_caching_unsubscribe(), stasis_forward_cancel(), and stasis_cp_single::topic_cached.
Referenced by endpoint_dtor().
struct stasis_cp_single* stasis_cp_sink_create | ( | struct stasis_cp_all * | all, |
const char * | name | ||
) |
Create a sink in the cache pattern.
Create the 'one' but do not automatically forward to the all's topic. This is useful when aggregating other topic's messages created with stasis_cp_single_create
in another caching topic without replicating those messages in the all's topics.
Dispose of using stasis_cp_single_unsubscribe().
all | Corresponding all side. |
name | Base name for the topics. |
Definition at line 162 of file stasis_cache_pattern.c.
References ao2_ref, ao2_t_alloc, stasis_cp_all::cache, NULL, one_dtor(), stasis_caching_topic_create(), stasis_topic_create(), stasis_cp_single::topic, and stasis_cp_single::topic_cached.
Referenced by endpoint_internal_create(), and stasis_cp_single_create().