Ejemplo n.º 1
0
  /**
   * The wakeup option is used internally when the kernel is broadcasting out to a bunch of
   * endpoints and doesn't want to necessarily wakeup right away.
   */
  protected void send(ByteBuffer data, boolean copy, boolean wakeup) {
    // We create a ByteBuffer per endpoint since we
    // use it to track the data sent to each endpoint
    // separately.
    ByteBuffer buffer;
    if (!copy) {
      buffer = data;
    } else {
      // Copy the buffer
      buffer = ByteBuffer.allocate(data.remaining());
      buffer.put(data);
      buffer.flip();
    }

    // Queue it up
    outbound.add(buffer);

    if (wakeup) kernel.wakeupSelector();
  }
Ejemplo n.º 2
0
  public void close(boolean flushData) {
    if (flushData) {
      closing = true;

      // Enqueue a close marker message to let the server
      // know we should close
      send(CLOSE_MARKER, false, true);

      return;
    }

    try {
      // Note: even though we may be disconnected from the socket.isConnected()
      // standpoint, it's still safest to tell the kernel so that it can be sure
      // to stop managing us gracefully.
      kernel.closeEndpoint(this);
    } catch (IOException e) {
      throw new KernelException("Error closing endpoint for socket:" + socket, e);
    }
  }