Skip to content
Browse files

Added support for gproc

  • Loading branch information...
1 parent 9ca4668 commit 764abae3fe9023fa3d2addffe165c904427a7dcb @ericmoritz committed Jun 3, 2012
View
40 apps/twitterlinks/ebin/twitterlinks.appup
@@ -1,40 +0,0 @@
-% -* erlang -*-
-{"0.2",
- [{"1",
- [
- {add_module, twitterlinks_delicious_request},
- {add_module, twitterlinks_accounts},
- {load_module, twitterlinks},
-
- {load_module, twitterlinks_app},
-
- {update, twitterlinks_twitter, {advanced,[]},
- [twitterlinks,
- twitterlinks_delicious,
- twitterlinks_delicious_request]},
-
- {update, twitterlinks_delicious, {advanced, []},
- [twitterlinks,
- twitterlinks_delicious,
- twitterlinks_delicious_request]},
-
- {update, twitterlinks_sup, supervisor}]},
- {"1",
- [
- {delete_module, twitterlinks_delicious_request},
- {delete_module, twitterlinks_accounts},
- {load_module, twitterlinks},
- {load_module, twitterlinks_app},
-
- {update, twitterlinks_twitter, {advanced,[]},
- [twitterlinks,
- twitterlinks_delicious,
- twitterlinks_delicious_request]},
-
- {update, twitterlinks_delicious, {advanced, []},
- [twitterlinks,
- twitterlinks_delicious,
- twitterlinks_delicious_request]},
-
- {update, twitterlinks_sup, supervisor}]}]}.
-
View
2 apps/twitterlinks/src/twitterlinks.app.src
@@ -1,7 +1,7 @@
{application, twitterlinks,
[
{description, "A Twitter to Delicious sync app"},
- {vsn, "0.2"},
+ {vsn, "2"},
{registered, []},
{applications, [
kernel,
View
5 apps/twitterlinks/src/twitterlinks_accounts.erl
@@ -8,7 +8,7 @@
%% API Function Exports
%% ------------------------------------------------------------------
--export([start_link/1, add_account/3, stop_account/1]).
+-export([start_link/0, add_account/3, stop_account/1]).
%% ------------------------------------------------------------------
%% gen_server Function Exports
@@ -21,7 +21,8 @@
%% API Function Definitions
%% ------------------------------------------------------------------
-start_link(Accounts) ->
+start_link() ->
+ {ok, Accounts} = application:get_env(twitterlinks, accounts),
gen_server:start_link({local, ?SERVER}, ?MODULE, [Accounts], []).
add_account(AccountId, TwitCred, DelCred) ->
View
3 apps/twitterlinks/src/twitterlinks_app.erl
@@ -10,8 +10,7 @@
%% ===================================================================
start(_StartType, _StartArgs) ->
- {ok, Accounts} = application:get_env(twitterlinks, accounts),
- twitterlinks_sup:start_link(Accounts).
+ twitterlinks_sup:start_link().
stop(_State) ->
ok.
View
11 apps/twitterlinks/src/twitterlinks_delicious.erl
@@ -31,7 +31,14 @@ start_link(AccountId, Username, Password) ->
gen_server:start_link(?MODULE, [AccountId, Username, Password], []).
create(AccountId, Username, Password) ->
- twitterlinks_delicious_sup:start_child(AccountId, Username, Password).
+ case pid_for(AccountId) of
+ undefined ->
+ twitterlinks_delicious_sup:start_child(AccountId, Username,
+ Password);
+ Pid ->
+ {ok, Pid}
+ end.
+
publish_url(AccountId, Url, Description, TagList) ->
Pid = pid_for(AccountId),
@@ -46,7 +53,7 @@ stop(AccountId) ->
end.
pid_for(AccountId) ->
- gproc:lookup_pid({n,l, {delicious, account_id, AccountId}}).
+ gproc:where({n,l, {delicious, account_id, AccountId}}).
%% ------------------------------------------------------------------
%% gen_server Function Definitions
View
10 apps/twitterlinks/src/twitterlinks_sup.erl
@@ -4,7 +4,7 @@
-behaviour(supervisor).
%% API
--export([start_link/1]).
+-export([start_link/0]).
%% Supervisor callbacks
-export([init/1]).
@@ -16,17 +16,17 @@
%% API functions
%% ===================================================================
-start_link(Accounts) ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, [Accounts]).
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
%% ===================================================================
%% Supervisor callbacks
%% ===================================================================
-init([Accounts]) ->
+init([]) ->
DeliciousSup = ?CHILD(twitterlinks_delicious_sup, supervisor, []),
TwitterSup = ?CHILD(twitterlinks_twitter_sup, supervisor, []),
- AccountsWorker = ?CHILD(twitterlinks_accounts, worker, [Accounts]),
+ AccountsWorker = ?CHILD(twitterlinks_accounts, worker, []),
Children = [DeliciousSup, TwitterSup, AccountsWorker],
RestartStrategy = {one_for_all, 4, 3600},
View
11 apps/twitterlinks/src/twitterlinks_twitter.erl
@@ -30,11 +30,16 @@ start_link(AccountId, Username, Password, UserId) ->
[]).
create(AccountId, Username, Password, UserId) ->
- twitterlinks_twitter_sup:start_child(AccountId,
- Username, Password, UserId).
+ case pid_for(AccountId) of
+ undefined ->
+ twitterlinks_twitter_sup:start_child(AccountId,
+ Username, Password, UserId);
+ Pid ->
+ {ok, Pid}
+ end.
pid_for(AccountId) ->
- gproc:lookup_pid({n,l, {twitter, account_id, AccountId}}).
+ gproc:where({n,l, {twitter, account_id, AccountId}}).
stop(AccountId) ->
case pid_for(AccountId) of

0 comments on commit 764abae

Please sign in to comment.
Something went wrong with that request. Please try again.