public PoolBuffer allocate() { final PoolBuffer buffer = (isDirect || FORCE_BYTE_BUFFER_BASED_BUFFERS) ? // if isDirect || FORCE_BYTE_BUFFER - allocate ByteBufferWrapper new PoolByteBufferWrapper(isDirect ? ByteBuffer.allocateDirect(bufferSize) : ByteBuffer.allocate(bufferSize), this) : // otherwise use HeapBuffer new PoolHeapBuffer(new byte[bufferSize], this); ProbeNotifier.notifyBufferAllocated(monitoringConfig, bufferSize); return buffer; }
private void dispose0() { // check shared counter optimistically boolean isNotShared = shareCount.get() == 0; if (!isNotShared) { // try pessimistic check using CAS loop isNotShared = (shareCount.getAndDecrement() == 0); if (isNotShared) { // if the former check is true - the shared counter is negative, // so we have to reset it shareCount.set(0); } } if (isNotShared) { // we can now safely return source back to the queue source.returnToPool(); } }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
private HeapBuffer asReadOnlyBuffer(final int offset, final int cap) { checkDispose(); onShareHeap(); final HeapBuffer b = new ReadOnlyHeapBuffer(heap, offset, cap) { @Override public void dispose() { super.dispose(); PoolHeapBuffer.this.dispose0(); } @Override protected void onShareHeap() { PoolHeapBuffer.this.onShareHeap(); } @Override protected HeapBuffer createHeapBuffer(final int offset, final int capacity) { return PoolHeapBuffer.this.asReadOnlyBuffer(offset, capacity); } }; b.allowBufferDispose(true); return b; }
/** * Create a new {@link HeapBuffer} based on the current heap. * * @param offs relative offset, the absolute value will calculated as (this.offset + offs) * @param capacity the capacity of this {@link HeapBuffer}. * * @return a new {@link HeapBuffer} based on the the method arguments. */ @Override protected HeapBuffer createHeapBuffer(final int offs, final int capacity) { onShareHeap(); final PoolHeapBuffer b = new PoolHeapBuffer(heap, offs + offset, capacity, null, // don't keep track of the owner for child buffers source, // pass the 'parent' buffer along shareCount); // pass the shareCount b.allowBufferDispose(true); return b; }
/** * Create a new {@link HeapBuffer} based on the current heap. * * @param offs relative offset, the absolute value will calculated as (this.offset + offs) * @param capacity the capacity of this {@link HeapBuffer}. * * @return a new {@link HeapBuffer} based on the the method arguments. */ @Override protected HeapBuffer createHeapBuffer(final int offs, final int capacity) { onShareHeap(); final PoolHeapBuffer b = new PoolHeapBuffer(heap, offs + offset, capacity, null, // don't keep track of the owner for child buffers source, // pass the 'parent' buffer along shareCount); // pass the shareCount b.allowBufferDispose(true); return b; }
/** * Create a new {@link HeapBuffer} based on the current heap. * * @param offs relative offset, the absolute value will calculated as (this.offset + offs) * @param capacity the capacity of this {@link HeapBuffer}. * * @return a new {@link HeapBuffer} based on the the method arguments. */ @Override protected HeapBuffer createHeapBuffer(final int offs, final int capacity) { onShareHeap(); final PoolHeapBuffer b = new PoolHeapBuffer(heap, offs + offset, capacity, null, // don't keep track of the owner for child buffers source, // pass the 'parent' buffer along shareCount); // pass the shareCount b.allowBufferDispose(true); return b; }
/** * Create a new {@link HeapBuffer} based on the current heap. * * @param offs relative offset, the absolute value will calculated as (this.offset + offs) * @param capacity the capacity of this {@link HeapBuffer}. * * @return a new {@link HeapBuffer} based on the the method arguments. */ @Override protected HeapBuffer createHeapBuffer(final int offs, final int capacity) { onShareHeap(); final PoolHeapBuffer b = new PoolHeapBuffer(heap, offs + offset, capacity, null, // don't keep track of the owner for child buffers source, // pass the 'parent' buffer along shareCount); // pass the shareCount b.allowBufferDispose(true); return b; }
/** * Create a new {@link HeapBuffer} based on the current heap. * * @param offs relative offset, the absolute value will calculated as (this.offset + offs) * @param capacity the capacity of this {@link HeapBuffer}. * * @return a new {@link HeapBuffer} based on the the method arguments. */ @Override protected HeapBuffer createHeapBuffer(final int offs, final int capacity) { onShareHeap(); final PoolHeapBuffer b = new PoolHeapBuffer(heap, offs + offset, capacity, null, // don't keep track of the owner for child buffers source, // pass the 'parent' buffer along shareCount); // pass the shareCount b.allowBufferDispose(true); return b; }
/** * Create a new {@link HeapBuffer} based on the current heap. * * @param offs relative offset, the absolute value will calculated as (this.offset + offs) * @param capacity the capacity of this {@link HeapBuffer}. * * @return a new {@link HeapBuffer} based on the the method arguments. */ @Override protected HeapBuffer createHeapBuffer(final int offs, final int capacity) { onShareHeap(); final PoolHeapBuffer b = new PoolHeapBuffer(heap, offs + offset, capacity, null, // don't keep track of the owner for child buffers source, // pass the 'parent' buffer along shareCount); // pass the shareCount b.allowBufferDispose(true); return b; }