commit | 32ba6e793460f9a4962cd5885fd14361554c52ed | [log] [tgz] |
---|---|---|
author | ILYA Khlopotov <iilyak@ca.ibm.com> | Wed Jun 10 16:02:59 2015 -0700 |
committer | ILYA Khlopotov <iilyak@ca.ibm.com> | Wed Jun 24 15:13:41 2015 -0700 |
tree | 5e66e9d38ca21ee2ec66a4fa42289758072f5a8c | |
parent | cf2e463b22c3629ae1dad1cc19bfdb68d001264e [diff] |
Initial version Add `ignore_providers` option Rename `hash(FilePath)` into `hashof_file(FilePath)` Use monitor to unsubscribe when subscriber die Rename couch_epi:all into couch_epi:dump Remove modules from dispatch on termination Add all/any convinence funs to couch_epi Document `ignore_providers` option Add childspec helper to _data_source and _functions Add license to test suite
couch_epi
is extensible plugin interface (EPI) for couchdb.
Service
's APIProvider
{service_id :: atom(), key :: term()}
- for couch_epi_data_source
service_id :: atom()
- for couch_epi_functions
couch_epi:get_handle(EpiKey)
We monitor the source of config information and have an ability to notify the subscriber. The source is either a file for a couch_epi_data_source
or module for couch_epi_functions
.
If the subscriber wants to receive notifications when the config has been updated it can use:
couch_epi:subscribe(App, Key, Module, Func, ExtraArgs)
The function would be called with following arguments
Fun(App :: app(), Key :: key(), OldData :: notification(), NewData :: notification(), ExtraArgs :: term()
The notification()
is either {data, term()}
or {modules, [module()]}
Any application that wants to register some configuration data for a service could add an entry in its supervision tree with something like:
{ appname_stats, {couch_epi_data_source, start_link, [ appname, {epi_key, {couch_stats, definitions}}, {priv_file, "couch_stats.cfg"}, [{interval, 100}] ]}, permanent, 5000, worker, dynamic }
Note we also support {file, FilePath}
instead of {priv_file, File}
When service provider wants to learn about all the installed config data for it to use it would then just do something like:
couch_epi:get(Handle, Service, Key)
There are also additional functions to get the same data in various formats
couch_epi:all(Handle)
- returns config data for all services for a given handlecouch_epi:get(Handle, Subscriber)
- returns config data for a given subscribercouch_epi:get_value(Handle, Subscriber, Key)
- returns config data for a given subscriber and keycouch_epi:by_key(Handle, Key)
- returns config data for a given keycouch_epi:by_key(Handle)
- returns config data grouped by keycouch_epi:by_source(Handle)
- returns config data grouped by source (subscriber)couch_epi:keys(Handle)
- returns list of configured keyscouch_epi:subscribers(Handle)
- return list of known subscribersAny application that wants to register some functions for a service could add an entry in its supervision tree with something like:
{ appname_stats, {couch_epi_functions, start_link, [ appname, {epi_key, my_service}, {modules, [my_module]}, [{interval, 100}] ]}, permanent, 5000, worker, dynamic }
Adding the entry would generate a dispatch methods for any exported function of modules passed.
When app wants to dispatch the call to all service providers it calls
couch_epi:apply(Handle, ServiceId, Function, Args, Opts)
There are multiple ways of doing the apply which is controlled by Opts
Notes:
concurrent
is incompatible with pipe