Created
July 21, 2010 02:43
-
-
Save tuulos/483964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handle_cast({update_config_table, Config}, S) -> | |
error_logger:info_report([{"Config table update"}]), | |
Update = fun({Host, Slots}, DNodes) -> | |
DNode = case gb_trees:lookup(Host, S#state.nodes) of | |
none -> | |
#dnode{name = Host, | |
slots = Slots, | |
node_mon = monitor(Host)}; | |
{value, N} -> | |
N#dnode{slots = Slots} | |
end, | |
gb_trees:insert(Host, DNode, DNodes) | |
end; | |
DNodes = lists:foldl(gb_trees:empty(), Update, Config), | |
lists:foreach(fun(DNode) -> | |
case gb_trees:lookup(DNode#dnode.name, DNodes) of | |
none -> | |
unlink(DNode#dnode.node_mon), | |
exit(DNode#dnode.node_mon, kill); | |
_ -> ok | |
end | |
end, gb_trees:values(S#state.nodes)), | |
disco_proxy:update_nodes(gb_trees:keys(DNodes)), | |
update_nodes(DNodes), | |
{noreply, S#state{nodes = DNodes}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment