anchor.diff:      end.
   
   log_first_lines_from_port(Module, Port) ->
  -    log_port_lines(Module, Port,3).
  -
  -log_port_lines(_, _, 0) -> ok;
  -log_port_lines(M, Port, N) ->
  -    receive
  +    Pid = log_port_lines(Module, Port, undefined, 1),
  +    log_port_lines(Module, Port, undefined, 2),
  +    Pid.
  +
  +log_port_lines(_, _, R, 0) -> R;
  +log_port_lines(M, Port, _, N) ->
  +    R = receive
           {Port, {data, {_Type, Data}}} ->
  -            lager:info("[gen_java][~p] startup: ~p", [M, Data])
  +            lager:info("[gen_java][~p] startup: ~p", [M, Data]),
  +            Data
       after
           20000 ->
  -            lager:info("[gen_java] didn't output anything on startup")
  +            lager:info("[gen_java] didn't output anything on startup"),
  +            undefined
       end,
  -    log_port_lines(M, Port, N-1).
  +    log_port_lines(M, Port, R, N-1).
  
positive.code:         ok ->
              rpc:call(Nodename, erlang, link, [self()]),
              erlang:monitor_node(Nodename, true),
              init_callback( State#gen_java_state{ port = Port });
          timeout ->
              {stop, timeout}
      end.
  
negative.code: terminate(_Reason, #gen_java_state { nodename = undefined }) ->
      %% Java server isn't running; nothing to do
      ok;
  terminate(_Reason, #gen_java_state{ pid = Pid, nodename = N, port = Port, module = M }) ->
      %% Java server appears to still be running; send kill signal and wait
      %% for it to shutdown.
      unlink(Port),
      lager:info("[gen_java][~p] Sending `rex ! stop` from terminate", [M]),
      {rex, N} ! stop,
      safe_port_close(Port),
      %% Sometimes it needs to be put down
      os:cmd(?FMT("kill ~s", [Pid])),
      ok.
  
  -spec code_change(term(), #gen_java_state{}, term()) -> {ok, #gen_java_state{}}.
  