Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (61 sloc) 3.244 kB
d036073 BossDB is now its own project
Evan Miller authored
1 -module(boss_news).
2
3 -export([start/0, start/1]).
4
5 -export([stop/0]).
6
7 -export([watch/2, watch/3, watch/4]).
8
9 -export([set_watch/3, set_watch/4, set_watch/5]).
10
11 -export([cancel_watch/1, extend_watch/1]).
12
13 -export([deleted/2, updated/3, created/2]).
14
15 -export([reset/0, dump/0]).
16
17 -define(TRILLION, 1000 * 1000 * 1000 * 1000).
18
19 start() ->
20 start([]).
21
22 start(Options) ->
23 boss_news_sup:start_link(Options).
24
25 stop() ->
26 ok.
27
28 %% @doc Watch records and attributes described by `TopicString', and execute
29 %% `CallBack(Event, EventInfo)' each time any of them changes.
30 %% Note that the callback should be specified as a named fun and not a closure,
31 %% or you may experience unexpected results during code reloads.
32 %% @spec watch( TopicString :: string(), CallBack ) -> {ok, WatchId} | {error, Reason}
33 watch(TopicString, CallBack) ->
34 watch(TopicString, CallBack, []).
35
36 %% @doc Same as `watch/2', except that `UserInfo' will be passed as a third argument
37 %% to the callback if the callback takes three arguments.
38 %% @spec watch( TopicString :: string(), CallBack, UserInfo ) -> {ok, WatchId} | {error, Reason}
39 watch(TopicString, CallBack, UserInfo) ->
40 watch(TopicString, CallBack, UserInfo, ?TRILLION).
41
42 %% @doc Same as `watch/3', except that the watch expires after `TTL' seconds.
43 %% @spec watch( TopicString :: string(), CallBack, UserInfo, TTL) -> {ok, WatchId} | {error, Reason}
44 watch(TopicString, CallBack, UserInfo, TTL) ->
45 gen_server:call({global, ?MODULE}, {watch, TopicString, CallBack, UserInfo, TTL}).
46
47 %% @doc Create or replace a watch with `WatchId'.
48 %% @spec set_watch( WatchId, TopicString::string(), CallBack ) -> ok | {error, Reason}
49 set_watch(WatchId, TopicString, CallBack) ->
50 set_watch(WatchId, TopicString, CallBack, []).
51
52 %% @doc Same as `set_watch/3', except that `UserInfo' is passed to the callback.
53 %% @spec set_watch( WatchId, TopicString::string(), CallBack, UserInfo ) -> ok | {error, Reason}
54 set_watch(WatchId, TopicString, CallBack, UserInfo) ->
55 set_watch(WatchId, TopicString, CallBack, UserInfo, ?TRILLION).
56
57 %% @doc Same as `set_watch/4', except that the watch expires after `TTL' seconds.
58 %% @spec set_watch( WatchId, TopicString::string(), CallBack, UserInfo, TTL ) -> ok | {error, Reason}
59 set_watch(WatchId, TopicString, CallBack, UserInfo, TTL) ->
60 gen_server:call({global, ?MODULE}, {set_watch, WatchId, TopicString, CallBack, UserInfo, TTL}).
61
62 %% @doc Cancel an existing watch identified by `WatchId'.
63 %% @spec cancel_watch( WatchId ) -> ok | {error, Reason}
64 cancel_watch(WatchId) ->
65 gen_server:call({global, ?MODULE}, {cancel_watch, WatchId}).
66
67 %% @doc Extend an existing watch by the time-to-live specified at creation time.
68 %% @spec extend_watch( WatchId ) -> ok | {error, Reason}
69 extend_watch(WatchId) ->
70 gen_server:call({global, ?MODULE}, {extend_watch, WatchId}).
71
72 deleted(Id, Attrs) ->
73 gen_server:call({global, ?MODULE}, {deleted, Id, Attrs}).
74
75 updated(Id, OldAttrs, NewAttrs) ->
76 gen_server:call({global, ?MODULE}, {updated, Id, OldAttrs, NewAttrs}).
77
78 created(Id, NewAttrs) ->
79 gen_server:call({global, ?MODULE}, {created, Id, NewAttrs}).
80
81 reset() ->
82 gen_server:call({global, ?MODULE}, reset).
83
84 dump() ->
85 gen_server:call({global, ?MODULE}, dump).
Something went wrong with that request. Please try again.