anchor.diff:  %% gen_server handlers
   
   start_link() ->
  -    %% If it's already running elsewhere in the cluster, just monitor
  -    %% the existing process.
  -    case gen_server:start_link({global, ?MODULE}, ?MODULE, [], []) of
  -        {error, {already_started, Pid}} ->
  -            {ok, spawn_link(fun () -> misc:wait_for_process(Pid, infinity) end)};
  -        X -> X
  -    end.
  +    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
   
   init([]) ->
       self() ! acquire_initial_status,
       {ok, #state{nodes=dict:new()}}.
   
  -handle_call(get_nodes, _From, State) ->
  -    %% In case the doctor gets slow, collect any heartbeats from the queue so we
  -    %% don't think the status is stale
  -    Nodes = collect_status(State#state.nodes),
  +handle_call(get_nodes, _From, #state{nodes=Nodes} = State) ->
       Now = erlang:now(),
       LiveNodes = [node()|nodes()],
       Nodes1 = dict:map(
  
positive.code: %% API
  
  heartbeat(Status) ->
      heartbeat(node(), Status).
  
  heartbeat(Node, Status) ->
      catch global:send(?MODULE, {heartbeat, Node, Status}).
  
  get_nodes() ->
      try gen_server:call({global, ?MODULE}, get_nodes) of
          Nodes -> Nodes
      catch
          _:_ -> dict:new()
      end.
  
  
  %% Internal functions
  
  collect_status(Nodes) ->
      receive
          {heartbeat, Name, Status} ->
              Nodes1 = update_status(Name, Status, Nodes),
              collect_status(Nodes1)
      after 0 ->
              Nodes
      end.
  
  
  update_status(Name, Status, Dict) ->
      Node = [{last_heard, erlang:now()} | Status],
      dict:store(Name, Node, Dict).
  
negative.code:                                [ down | Stale ]
                         end
                 end, Nodes),
      {reply, Nodes1, State}.
  
  
  handle_cast({heartbeat, Name, Status}, State) ->
      Nodes = update_status(Name, Status, State#state.nodes),
      {noreply, State#state{nodes=Nodes}};
  
  handle_cast(Msg, State) ->
      ?log_warning("Unexpected cast: ~p", [Msg]),
      {noreply, State}.
  
  
  