private void start(ThreadFactory f) { // only start once.... if (active.compareAndSet(false, true)) { connectionPeerReceiver = new ConnectionPeerReceiver(f); connectionPeerReceiver.start(); if (isSenderUsed()) { sender = new Sender(f, getSenderQueueSize()); sender.start(); } } }
public void close() throws IOException { // can close even if start was never called... send_lock.lock(); try { connectionPeerReceiver.stop(); if (isSenderUsed()) { sender.stop(); } Util.close(sock); Util.close(out); Util.close(in); } finally { send_lock.unlock(); } mapper.notifyConnectionClosed(peer_addr); }
public boolean isOpen() { return isConnected() && (!isSenderUsed() || sender.isRunning()) && (connectionPeerReceiver != null && connectionPeerReceiver.isRunning()); }