/** * @param data Guaranteed to be non null * @param offset * @param length */ public void send(byte[] data, int offset, int length) throws Exception { if (sender != null) { byte[] copy = new byte[length]; System.arraycopy(data, offset, copy, 0, length); sender.addToQueue(new Buffer(copy, 0, length)); } else _send(data, offset, length, true, true); }
public void start() { if (receiver != null) receiver.stop(); receiver = new Receiver(server.factory).start(); if (isSenderUsed()) { if (sender != null) sender.stop(); sender = new Sender(server.factory, server.sendQueueSize()).start(); } }
/** * @param data Guaranteed to be non null * @param offset * @param length */ private void send(byte[] data, int offset, int length) throws Exception { if (isSenderUsed()) { // we need to copy the byte[] buffer here because the original buffer might get // changed meanwhile byte[] tmp = new byte[length]; System.arraycopy(data, offset, tmp, 0, length); sender.addToQueue(tmp); } else { _send(data, offset, length, true); } }
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 void close() throws IOException { send_lock.lock(); try { Util.close(out, in, sock); if (receiver != null) { receiver.stop(); receiver = null; } if (sender != null) { sender.stop(); sender = null; } } finally { send_lock.unlock(); } }
public boolean isOpen() { return isConnected() && (!isSenderUsed() || sender.isRunning()) && (connectionPeerReceiver != null && connectionPeerReceiver.isRunning()); }
/** * Test if substrate is ready to send more packets. * * @return true if substrate is ready */ public boolean ready() { return sndr.ready(); }
/** * Send a packet. * * @param p is a packet to be sent */ public void send(Packet p) { sndr.send(p); }
/** Wait for Substrate to stop. */ public void join() throws Exception { sndr.join(); rcvr.join(); }
/** Start Substrate running. */ public void start() { sndr.start(); rcvr.start(); }