GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: A new revision of Fuzed, the Erlang-based frontend for web apps. Check out the mailing list at http://groups.google.com/group/fuzed
Clone URL: git://github.com/KirinDave/fuzed.git
KirinDave (author)
Fri Jun 27 21:34:48 -0700 2008
commit  ef5bbabf4e76a601026c7ef623c3439279ef2ffc
tree    e58bfc500bdd0ca9a08e8ede3de14b58cdf45bda
parent  b007a546552f110afe70b5a185a8b316f77a9f0e
fuzed / elibs / distributed_resource_fountain.erl
100644 51 lines (40 sloc) 1.649 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-module(distributed_resource_fountain).
-behavior(gen_leader).
 
-compile(export_all).
 
-record(s, {details_pool_dict = dict:new(),
                pool_details_dict = dict:new(),
                lookup_cache_dict = dict:new(),
                total_node_dict = dict:new(),
                virgin = true}).
 
 
init([]) ->
  process_flag(trap_exit, true),
  error_logger:info_msg("Resource fountain (~p) starting...~n", node(self())),
  {ok, #s{}}.
 
% Called when someone becomes a leader. Really all it should do is dump state.
elected(State, _Election) ->
  error_logger:info_msg("DiReFo: ~p elected. Other nodes will be given state.~n",
                        node(self())),
  {ok, State, State}.
 
surrendered(State, LeaderState, _Election) ->
  reconstitute_state(State, LeaderState).
 
handle_DOWN(Node, State, _E) ->
    io:format("~p awknowledges that ~p went down!", [node(self()), Node]),
    {ok, State}. % No need to broadcast here.
 
handle_leader_call({add_node, Details, Node}, _From, State, _Election) when is_pid(Node) ->
  case find_pool_for_details(Details, State) of
    none ->
      % We'll create one, stash it, and tell everyone else to make a pool
      % and stash it.
      {Pool, UpdatedState} = create_pool_for_details(Details, State),
      resource_pool:add(Pool, Node),
      link(Node),
      {reply, Pool,
              {make_pool_and_add_node, Details, Node},
              track_node(Node, UpdatedState)};
    Pool when is_pid(Pool) ->
      link(Node),
      {reply, Pool,
              {add_node_to_details_pool, Details, Node},
              track_node(Node)}
  end;
handle_leader_call() ->