diff options
author | Nathan Lasseter <nathan.je.lasseter@googlemail.com> | 2011-01-27 21:57:12 +0000 |
---|---|---|
committer | Nathan Lasseter <nathan.je.lasseter@googlemail.com> | 2011-01-27 21:57:12 +0000 |
commit | d3dd0ee7cce770cc7b5089943d043a9b3da0af50 (patch) | |
tree | ad343f54c9fedda517a346e3aff8f1681437a464 | |
parent | 6d2ccec261ead5f3f3d62aa4d42735930f44e5c8 (diff) |
RPCs and no registering.
-rw-r--r-- | erlbal.erl | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -1,10 +1,18 @@ -module(erlbal). --export([make_request/2, start_bal/1, kill_bal/1, start_server/2]). +-export([make_request/2, start_bal/0, stop_bal/1, start_server/2, stop_server/2, list_servers/1]). start_server(Balancer, Fun) -> PID = spawn(fun() -> server_loop(Balancer, Fun) end), Balancer ! {add_node, PID}. +stop_server(Balancer, PID) -> + Balancer ! {del_node, PID}, + PID ! die. + +list_servers(Balancer) -> + Balancer ! {list_nodes, self()}, + receive Nodes -> Nodes end. + server_loop(Balancer, Fun) -> receive {request, From, ARGS} -> @@ -15,10 +23,10 @@ server_loop(Balancer, Fun) -> ok end. -start_bal(Name) -> - register(Name, spawn(fun() -> bal_loop([], 1) end)). +start_bal() -> + spawn(fun() -> bal_loop([], 1) end). -kill_bal(Balancer) -> +stop_bal(Balancer) -> Balancer ! die, unregister(Balancer). @@ -52,7 +60,4 @@ bal_loop(Serverlist, Nextserver) -> make_request(Balancer, ARGS) -> Balancer ! {request, self(), ARGS}, - receive - Ret -> - Ret - end. + receive Ret -> Ret end. |