private void receiveCommands() { while (!requestStop) { try { Map<String, Object> input = connector.receive(); if (input == null) break; int serial = ((Number) input.get("serial")).intValue(); if (inSerial++ != serial) throw new ProtocolException("farcall sync lost"); Number ref = (Number) input.get("ref"); if (ref != null) { processReply(input, ref.intValue()); } else { processCommand(input, serial); } } catch (EOFException e) { log.i("closing farcall instance on eof encountered"); close(); } catch (IOException e) { log.wtf("internal error", e); break; } } close(); }