anchor.diff:           recv_msg/1,
            send_msg/2,
            send_msg/3,
  -         heartbeat/1,
            status/1,
            watch/1,
  -         aborted/1,
            rehab/1]).
   
   %% States
   -export([idle/2,
            post_init/2,
  -         running/2,
            rehab/2]).
   
   -record(state, {node_ref              :: node_ref(),
  
positive.code: idle(do_rehab, State) ->
      State1 = force_abort(State),
      {next_state, state_transition(idle, rehab, State1), State1};
  idle({job, Job}, State) ->
      State1 = State#state{job=Job, availability=unavailable},
      {next_state, state_transition(idle, running, State1), State1};
  idle(aborted, State) ->
      {next_state, idle, State}.
  
  running(do_rehab, State) ->
      State1 = force_abort(State),
      {next_state, state_transition(running, rehab, State1), State1};
  running(aborted, #state{node_ref=NodeRef}=State) ->
      lager:debug("~p aborted during job.~n", [NodeRef]),
      State1 = State#state{job=undefined, availability=available},
      {next_state, state_transition(running, idle, State1), State1};
  running({complete, Job}, #state{job=Job, node_ref=NodeRef}=State) ->
      lager:info("~p completed job.~n", [NodeRef]),
      State1 = State#state{job=undefined, availability=available},
      {next_state, state_transition(running, idle, State1), State1}.
  
  handle_event(_Event, StateName, State) ->
      {next_state, StateName, State}.
  
negative.code: 
  watch(NodeRef) ->
      call(NodeRef, {watch, self()}).
  
  rehab(NodeRef) ->
      cast(NodeRef, do_rehab).
  