Permalink
Browse files

simplify the CerebrateDnssd code

  • Loading branch information...
1 parent f45d829 commit 516793e06660477ebd39ac4071ee40e3cca12465 @clofresh committed Apr 13, 2012
Showing with 6 additions and 30 deletions.
  1. +2 −8 src/cerebrate.ex
  2. +4 −22 src/cerebrate_checks.ex
View
10 src/cerebrate.ex
@@ -77,14 +77,8 @@ defmodule CerebrateWeb do
[metric, float_to_list(value)]
end
- Process.whereis(:cerebrate_dnssd) <- {:query, Process.self()}
- peers = receive do
- match: dnssd_state
- Enum.map Erlang.dict.fetch(:peers, dnssd_state), fn({name, type, domain}) ->
- [name, type, domain]
- end
- after: 2000
- raise "Could not get peers"
+ peers = Enum.map CerebrateDnssd.get_peers(), fn({name, type, domain}) ->
+ [name, type, domain]
end
IO.inspect peers
reply = ["Data:", output, peers]
View
26 src/cerebrate_checks.ex
@@ -3,12 +3,6 @@ defmodule CerebrateDnssd do
@browse_timeout 1000
def start_link(config) do
- pid = spawn_link CerebrateDnssd, :start, [config]
- Process.register :cerebrate_dnssd, pid
- {:ok, pid}
- end
-
- def start(config) do
rpc_port = config[:rpc_port]
Erlang.dnssd.register "Cerebrate-#{rpc_port}", CerebrateDnssd.__info__(:data)[:service_type], rpc_port
receive do
@@ -17,36 +11,25 @@ defmodule CerebrateDnssd do
match: {:dnssd, ref, {:register, :remove, result}}
IO.puts "Unexpected remove result: #{inspect(result)}"
end
- run Erlang.dict.new()
- end
-
- def run(state) do
- new_state = Erlang.dict.store :peers, get_peers(), state
- #IO.inspect Erlang.dict.fetch :peers, new_state
- receive do
- match: {:query, caller}
- caller <- new_state
- after: 1000
- #IO.puts "No calls after 1000ms"
- end
- run new_state
+ {:ok, Process.self()}
end
-
@doc """
Makes a dnssd browse request for all the services of type @service_type.
Returns [{ServiceName, ServiceType, Domain}]
"""
- defp get_peers() do
+ def get_peers() do
Erlang.dnssd.browse(CerebrateDnssd.__info__(:data)[:service_type])
get_peers([])
end
defp get_peers(current_peers) do
receive do
match: {:dnssd, ref, {:browse, :add, result}}
+ IO.puts "browse"
get_peers [result | current_peers]
after: CerebrateDnssd.__info__(:data)[:browse_timeout]
+ IO.puts "timeout"
current_peers
end
end
@@ -86,7 +69,6 @@ end
defmodule CerebrateCollector do
def start_link(config) do
pid = spawn_link CerebrateCollector, :start, [config]
- Process.register :collector, pid
{:ok, pid}
end

0 comments on commit 516793e

Please sign in to comment.