Пример #1
0
 /**
  * @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);
 }
Пример #2
0
  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();
    }
  }
Пример #3
0
 /**
  * @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);
   }
 }
Пример #4
0
    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();
        }
      }
    }
Пример #5
0
 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);
 }
Пример #6
0
 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();
   }
 }
Пример #7
0
 public boolean isOpen() {
   return isConnected()
       && (!isSenderUsed() || sender.isRunning())
       && (connectionPeerReceiver != null && connectionPeerReceiver.isRunning());
 }
Пример #8
0
 /**
  * Test if substrate is ready to send more packets.
  *
  * @return true if substrate is ready
  */
 public boolean ready() {
   return sndr.ready();
 }
Пример #9
0
 /**
  * Send a packet.
  *
  * @param p is a packet to be sent
  */
 public void send(Packet p) {
   sndr.send(p);
 }
Пример #10
0
 /** Wait for Substrate to stop. */
 public void join() throws Exception {
   sndr.join();
   rcvr.join();
 }
Пример #11
0
 /** Start Substrate running. */
 public void start() {
   sndr.start();
   rcvr.start();
 }