Beispiel #1
0
  protected void send(Message message, boolean waitForConnected) {
    checkRunning();

    if (waitForConnected) {
      // Make sure we aren't still connecting
      waitForConnected();
    }

    ByteBuffer buffer = dataBuffer.get();
    if (buffer == null) {
      buffer = ByteBuffer.allocate(65536 + 2);
      dataBuffer.set(buffer);
    }
    buffer.clear();

    // Convert the message to bytes
    buffer = MessageProtocol.messageToBuffer(message, buffer);

    // Since we share the buffer between invocations, we will need to
    // copy this message's part out of it.  This is because we actually
    // do the send on a background thread.
    byte[] temp = new byte[buffer.remaining()];
    System.arraycopy(buffer.array(), buffer.position(), temp, 0, buffer.remaining());
    buffer = ByteBuffer.wrap(temp);

    if (message.isReliable() || fast == null) {
      if (reliable == null) throw new RuntimeException("No reliable connector configured");
      reliableAdapter.write(buffer);
    } else {
      fastAdapter.write(buffer);
    }
  }