Example #1
0
  /**
   * Releases a temporary buffer by returning to the cache or freeing it. If returning to the cache
   * then insert it at the end. This makes it suitable for scatter/gather operations where the
   * buffers are returned to cache in same order that they were obtained.
   */
  static void offerLastTemporaryDirectBuffer(ByteBuffer buf) {
    // If the buffer is too large for the cache we don't have to
    // check the cache. We'll just free it.
    if (isBufferTooLarge(buf)) {
      free(buf);
      return;
    }

    assert buf != null;
    BufferCache cache = bufferCache.get();
    if (!cache.offerLast(buf)) {
      // cache is full
      free(buf);
    }
  }