/** * Allocate a {@link Buffer} using the provided {@link ThreadLocalPool}. * * @param threadLocalCache the {@link ThreadLocalPool} to allocate from. * @param size the amount to allocate. * * @return an memory buffer, or <code>null</code> if the requested size * exceeds the remaining free memory of the {@link ThreadLocalPool}. */ protected Object allocateFromPool(final ThreadLocalPool threadLocalCache, final int size) { if (threadLocalCache.remaining() >= size) { ProbeNotifier.notifyBufferAllocatedFromPool(monitoringConfig, size); return threadLocalCache.allocate(size); } return null; }
@Override @SuppressWarnings("unchecked") public void trim() { final int sizeToReturn = visible.capacity() - visible.position(); if (sizeToReturn > 0) { final ThreadLocalPool<ByteBuffer> threadLocalCache = getByteBufferThreadLocalPool(); if (threadLocalCache != null) { if (threadLocalCache.isLastAllocated(visible)) { visible.flip(); visible = visible.slice(); threadLocalCache.reduceLastAllocated(visible); return; } else if (threadLocalCache.wantReset(sizeToReturn)) { visible.flip(); final ByteBuffer originalByteBuffer = visible; visible = visible.slice(); originalByteBuffer.position(originalByteBuffer.limit()); originalByteBuffer.limit(originalByteBuffer.capacity()); threadLocalCache.reset(originalByteBuffer); return; } } } super.trim(); }
@Override @SuppressWarnings("unchecked") public void releaseByteBuffer(ByteBuffer byteBuffer) { ThreadLocalPool<ByteBuffer> memoryPool = getByteBufferThreadLocalPool(); if (memoryPool != null) { if (memoryPool.release((ByteBuffer) byteBuffer.clear())) { ProbeNotifier.notifyBufferReleasedToPool(monitoringConfig, byteBuffer.capacity()); } } }
@Override @SuppressWarnings("unchecked") public ByteBuffer reallocateByteBuffer(ByteBuffer oldByteBuffer, int newSize) { if (oldByteBuffer.capacity() >= newSize) return oldByteBuffer; final ThreadLocalPool<ByteBuffer> memoryPool = getByteBufferThreadLocalPool(); if (memoryPool != null) { final ByteBuffer newBuffer = memoryPool.reallocate(oldByteBuffer, newSize); if (newBuffer != null) { ProbeNotifier.notifyBufferAllocatedFromPool(monitoringConfig, newSize - oldByteBuffer.capacity()); return newBuffer; } } ByteBuffer newByteBuffer = allocateByteBuffer(newSize); oldByteBuffer.flip(); return newByteBuffer.put(oldByteBuffer); }
/** * Get the size of local thread memory pool. * * @return the size of local thread memory pool. */ public int getReadyThreadBufferSize() { ThreadLocalPool threadLocalPool = getThreadLocalPool(); if (threadLocalPool != null) { return threadLocalPool.remaining(); } return 0; }
@SuppressWarnings({"unchecked"}) private void reallocatePoolBuffer() { final ByteBuffer byteBuffer = allocateByteBuffer0(maxBufferSize); final ThreadLocalPool<ByteBuffer> threadLocalCache = getByteBufferThreadLocalPool(); if (threadLocalCache != null) { threadLocalCache.reset(byteBuffer); } }
@Override @SuppressWarnings("unchecked") public ByteBuffer reallocateByteBuffer(ByteBuffer oldByteBuffer, int newSize) { if (oldByteBuffer.capacity() >= newSize) return oldByteBuffer; final ThreadLocalPool<ByteBuffer> memoryPool = getByteBufferThreadLocalPool(); if (memoryPool != null) { final ByteBuffer newBuffer = memoryPool.reallocate(oldByteBuffer, newSize); if (newBuffer != null) { ProbeNotifier.notifyBufferAllocatedFromPool(monitoringConfig, newSize - oldByteBuffer.capacity()); return newBuffer; } } ByteBuffer newByteBuffer = allocateByteBuffer(newSize); oldByteBuffer.flip(); return newByteBuffer.put(oldByteBuffer); }
/** * Get the size of local thread memory pool. * * @return the size of local thread memory pool. */ public int getReadyThreadBufferSize() { ThreadLocalPool threadLocalPool = getThreadLocalPool(); if (threadLocalPool != null) { return threadLocalPool.remaining(); } return 0; }
@SuppressWarnings({"unchecked"}) private void reallocatePoolBuffer() { final ByteBuffer byteBuffer = allocateByteBuffer0(maxBufferSize); final ThreadLocalPool<ByteBuffer> threadLocalCache = getByteBufferThreadLocalPool(); if (threadLocalCache != null) { threadLocalCache.reset(byteBuffer); } }
@Override @SuppressWarnings("unchecked") public void trim() { final int sizeToReturn = visible.capacity() - visible.position(); if (sizeToReturn > 0) { final ThreadLocalPool<ByteBuffer> threadLocalCache = getByteBufferThreadLocalPool(); if (threadLocalCache != null) { if (threadLocalCache.isLastAllocated(visible)) { visible.flip(); visible = visible.slice(); threadLocalCache.reduceLastAllocated(visible); return; } else if (threadLocalCache.wantReset(sizeToReturn)) { visible.flip(); final ByteBuffer originalByteBuffer = visible; visible = visible.slice(); originalByteBuffer.position(originalByteBuffer.limit()); originalByteBuffer.limit(originalByteBuffer.capacity()); threadLocalCache.reset(originalByteBuffer); return; } } } super.trim(); }
/** * Allocate a {@link Buffer} using the provided {@link ThreadLocalPool}. * * @param threadLocalCache the {@link ThreadLocalPool} to allocate from. * @param size the amount to allocate. * * @return an memory buffer, or <code>null</code> if the requested size * exceeds the remaining free memory of the {@link ThreadLocalPool}. */ protected Object allocateFromPool(final ThreadLocalPool threadLocalCache, final int size) { if (threadLocalCache.remaining() >= size) { ProbeNotifier.notifyBufferAllocatedFromPool(monitoringConfig, size); return threadLocalCache.allocate(size); } return null; }
@Override @SuppressWarnings("unchecked") public void releaseByteBuffer(ByteBuffer byteBuffer) { ThreadLocalPool<ByteBuffer> memoryPool = getByteBufferThreadLocalPool(); if (memoryPool != null) { if (memoryPool.release((ByteBuffer) byteBuffer.clear())) { ProbeNotifier.notifyBufferReleasedToPool(monitoringConfig, byteBuffer.capacity()); } } }
@Override @SuppressWarnings("unchecked") public ByteBuffer reallocateByteBuffer(ByteBuffer oldByteBuffer, int newSize) { if (oldByteBuffer.capacity() >= newSize) return oldByteBuffer; final ThreadLocalPool<ByteBuffer> memoryPool = getByteBufferThreadLocalPool(); if (memoryPool != null) { final ByteBuffer newBuffer = memoryPool.reallocate(oldByteBuffer, newSize); if (newBuffer != null) { ProbeNotifier.notifyBufferAllocatedFromPool(monitoringConfig, newSize - oldByteBuffer.capacity()); return newBuffer; } } ByteBuffer newByteBuffer = allocateByteBuffer(newSize); oldByteBuffer.flip(); return newByteBuffer.put(oldByteBuffer); }
/** * Get the size of local thread memory pool. * * @return the size of local thread memory pool. */ public int getReadyThreadBufferSize() { ThreadLocalPool threadLocalPool = getThreadLocalPool(); if (threadLocalPool != null) { return threadLocalPool.remaining(); } return 0; }
@SuppressWarnings({"unchecked"}) private void reallocatePoolBuffer() { final ByteBuffer byteBuffer = allocateByteBuffer0(maxBufferSize); final ThreadLocalPool<ByteBuffer> threadLocalCache = getByteBufferThreadLocalPool(); if (threadLocalCache != null) { threadLocalCache.reset(byteBuffer); } }
@Override @SuppressWarnings("unchecked") public void trim() { final int sizeToReturn = visible.capacity() - visible.position(); if (sizeToReturn > 0) { final ThreadLocalPool<ByteBuffer> threadLocalCache = getByteBufferThreadLocalPool(); if (threadLocalCache != null) { if (threadLocalCache.isLastAllocated(visible)) { visible.flip(); visible = visible.slice(); threadLocalCache.reduceLastAllocated(visible); return; } else if (threadLocalCache.wantReset(sizeToReturn)) { visible.flip(); final ByteBuffer originalByteBuffer = visible; visible = visible.slice(); originalByteBuffer.position(originalByteBuffer.limit()); originalByteBuffer.limit(originalByteBuffer.capacity()); threadLocalCache.reset(originalByteBuffer); return; } } } super.trim(); }
/** * Allocate a {@link Buffer} using the provided {@link ThreadLocalPool}. * * @param threadLocalCache the {@link ThreadLocalPool} to allocate from. * @param size the amount to allocate. * * @return an memory buffer, or <code>null</code> if the requested size * exceeds the remaining free memory of the {@link ThreadLocalPool}. */ protected Object allocateFromPool(final ThreadLocalPool threadLocalCache, final int size) { if (threadLocalCache.remaining() >= size) { ProbeNotifier.notifyBufferAllocatedFromPool(monitoringConfig, size); return threadLocalCache.allocate(size); } return null; }
@Override @SuppressWarnings("unchecked") public void releaseByteBuffer(ByteBuffer byteBuffer) { ThreadLocalPool<ByteBuffer> memoryPool = getByteBufferThreadLocalPool(); if (memoryPool != null) { if (memoryPool.release((ByteBuffer) byteBuffer.clear())) { ProbeNotifier.notifyBufferReleasedToPool(monitoringConfig, byteBuffer.capacity()); } } }
@Override @SuppressWarnings("unchecked") public ByteBuffer reallocateByteBuffer(ByteBuffer oldByteBuffer, int newSize) { if (oldByteBuffer.capacity() >= newSize) return oldByteBuffer; final ThreadLocalPool<ByteBuffer> memoryPool = getByteBufferThreadLocalPool(); if (memoryPool != null) { final ByteBuffer newBuffer = memoryPool.reallocate(oldByteBuffer, newSize); if (newBuffer != null) { ProbeNotifier.notifyBufferAllocatedFromPool(monitoringConfig, newSize - oldByteBuffer.capacity()); return newBuffer; } } ByteBuffer newByteBuffer = allocateByteBuffer(newSize); oldByteBuffer.flip(); return newByteBuffer.put(oldByteBuffer); }
/** * Get the size of local thread memory pool. * * @return the size of local thread memory pool. */ public int getReadyThreadBufferSize() { ThreadLocalPool threadLocalPool = getThreadLocalPool(); if (threadLocalPool != null) { return threadLocalPool.remaining(); } return 0; }