Source:
<code>public void receiveConnection(Socket sock) throws ConfigException { <START> Long sid, protocolVersion; <END> InetSocketAddress electionAddr = null; try { DataInputStream din = new DataInputStream(sock.getInputStream()); protocolVersion = din.readLong(); if (protocolVersion >= 0) { sid = protocolVersion; } else { try { InitialMessage init = InitialMessage.parse(protocolVersion, din); sid = init.sid; electionAddr = init.electionAddr; } catch (InitialMessage.InitialMessageException ex) { LOG.error(ex.toString()); closeSocket(sock); return; } } if (sid == QuorumPeer.OBSERVER_ID) { sid = observerCounter--; LOG.info("Setting arbitrary identifier to observer: {}", sid); } } catch (IOException e) { closeSocket(sock); LOG.warn("Exception reading or writing challenge: {}", e.toString()); return; } if (sid < self.getId()) { SendWorker sw = senderWorkerMap.get(sid); if (sw != null) { sw.finish(); } LOG.debug("Create new connection to server: {}", sid); closeSocket(sock); if (electionAddr != null) { connectOne(sid, electionAddr); } else { connectOne(sid); } }else if (sid == self.getId()) { closeSocket(sock); throw new ConfigException(String.format("Appearing duplicate SID: %s", sid)); } else { SendWorker sw = new SendWorker(sock, sid); RecvWorker rw = new RecvWorker(sock, sid, sw); sw.setRecv(rw); SendWorker vsw = senderWorkerMap.get(sid); if (vsw != null) { vsw.finish(); } senderWorkerMap.put(sid, sw); queueSendMap.putIfAbsent(sid, new ArrayBlockingQueue<ByteBuffer>(SEND_CAPACITY)); sw.start(); rw.start(); } }</code><technical_language>removed extraneous null primitive long type, right? I gain of boxed types here. I a lot of boxing/unboxing in this method, simply int sid, protocolVersion; (this slightly falls "the fix if..." adage, ignore this for ;) )</technical_language>

Target:
public void receiveConnection(Socket sock) throws ConfigException { long sid, protocolVersion; InetSocketAddress electionAddr = null; try { DataInputStream din = new DataInputStream(sock.getInputStream()); protocolVersion = din.readLong(); if (protocolVersion >= 0) { sid = protocolVersion; } else { try { InitialMessage init = InitialMessage.parse(protocolVersion, din); sid = init.sid; electionAddr = init.electionAddr; } catch (InitialMessage.InitialMessageException ex) { LOG.error(ex.toString()); closeSocket(sock); return; } } if (sid == QuorumPeer.OBSERVER_ID) { sid = observerCounter--; LOG.info("Setting arbitrary identifier to observer: {}", sid); } } catch (IOException e) { closeSocket(sock); LOG.warn("Exception reading or writing challenge: {}", e.toString()); return; } if (sid < self.getId()) { SendWorker sw = senderWorkerMap.get(sid); if (sw != null) { sw.finish(); } LOG.debug("Create new connection to server: {}", sid); closeSocket(sock); if (electionAddr != null) { connectOne(sid, electionAddr); } else { connectOne(sid); } } else if (sid == self.getId()) { closeSocket(sock); throw new ConfigException(String.format("Duplicate SID %s found", sid)); } else { SendWorker sw = new SendWorker(sock, sid); RecvWorker rw = new RecvWorker(sock, sid, sw); sw.setRecv(rw); SendWorker vsw = senderWorkerMap.get(sid); if (vsw != null) { vsw.finish(); } senderWorkerMap.put(sid, sw); queueSendMap.putIfAbsent(sid, new ArrayBlockingQueue<ByteBuffer>(SEND_CAPACITY)); sw.start(); rw.start(); } }