private ByteBuffer createNewBufferIfAllowed(final int offset) {
        final int maxBufferCount = maxBufferCounts[offset];
        final int warningThreshold = warningThresholds[offset];
        final AtomicInteger bufferCounter = pooledBufferCounters[offset];
        final int roundedCapacity = bufferSizes[offset];

        ByteBuffer byteBuffer = null;

        while (true) {
            int currBufferCount = bufferCounter.get();


            if (currBufferCount < maxBufferCount) {
                final int newBufferCount = currBufferCount + 1;

                if (bufferCounter.compareAndSet(currBufferCount, newBufferCount)) {
                    // Succeeded in incrementing the count so we can create one
                    LOGGER.debug(() -> LogUtil.message("Creating new pooled buffer (capacity: {})",
                            ModelStringUtil.formatCsv(roundedCapacity)));
                    byteBuffer = ByteBuffer.allocateDirect(roundedCapacity);

                    if (newBufferCount == warningThreshold) {
                        LOGGER.warn("Hit {}% ({}) of the limit of {} for pooled buffers of size {}.",
                                byteBufferPoolConfigProvider.get().getWarningThresholdPercentage(),
                                warningThreshold,
                                maxBufferCount,
                                ModelStringUtil.formatCsv(bufferSizes[offset]));
                    } else if (newBufferCount == maxBufferCount) {
                        LOGGER.warn("Hit limit of {} for pooled buffers of size {}. " +
                                        "Future calls to the pool will create new buffers but excess buffers " +
                                        "will have to be freed rather than returned to the pool. This may incur a " +
                                        "performance overhead. Consider changing the pool settings.",
                                newBufferCount,
                                ModelStringUtil.formatCsv(roundedCapacity));
                    }

                    break;
                } else {
                    // CAS failed so another thread beat us, go round again.
                }
            } else {
                // At max count so can't add any more to the pool
                break;
            }
        }
        return byteBuffer;
    }
@param n The number to test
@return True if n is a power of ten, e.g. if n==10
stroom-bytebuffer/src/main/java/stroom/bytebuffer/ByteBufferPoolImpl4.java