private void allocateNewBuffer() { if (this.curBuf != null) { this.curBuf.flip();// On the current buf set limit = pos and pos = 0. } // Get an initial BB to work with from the pool this.curBuf = this.pool.getBuffer(); if (this.curBuf == null) { // No free BB at this moment. Make a new one. The pool returns off heap BBs. Don't make off // heap BB on demand. It is difficult to account for all such and so proper sizing of Max // direct heap size. See HBASE-15525 also for more details. // Make BB with same size of pool's buffer size. this.curBuf = ByteBuffer.allocate(this.pool.getBufferSize()); } else { this.bufsFromPool.add(this.curBuf); } this.allBufs.add(this.curBuf); }
private void initPoolWithAllBuffers(ByteBufferPool pool, int maxBuffersInPool) { ByteBuffer[] buffers = new ByteBuffer[maxBuffersInPool]; // Just call getBuffer() on pool 'maxBuffersInPool' so as to init all buffers and then put back // all. Makes pool with max #buffers. for (int i = 0; i < maxBuffersInPool; i++) { buffers[i] = pool.getBuffer(); } for (ByteBuffer buf : buffers) { pool.putbackBuffer(buf); } } }
private void testBBPool(int maxPoolSize, int bufferSize, boolean directByteBuffer) { ByteBufferPool pool = new ByteBufferPool(bufferSize, maxPoolSize, directByteBuffer); for (int i = 0; i < maxPoolSize; i++) { ByteBuffer buffer = pool.getBuffer(); assertEquals(0, buffer.position()); assertEquals(bufferSize, buffer.limit()); assertEquals(directByteBuffer, buffer.isDirect()); } assertEquals(0, pool.getQueueSize()); ByteBuffer bb = directByteBuffer ? ByteBuffer.allocate(bufferSize) : ByteBuffer.allocateDirect(bufferSize); pool.putbackBuffer(bb); assertEquals(0, pool.getQueueSize()); bb = directByteBuffer ? ByteBuffer.allocateDirect(bufferSize + 1) : ByteBuffer.allocate(bufferSize + 1); pool.putbackBuffer(bb); assertEquals(0, pool.getQueueSize()); } }
int remain = reqLen; ByteBuffer buf = null; while (remain >= minSizeForPoolUse && (buf = pool.getBuffer()) != null) { bbs.add(buf); remain -= pool.getBufferSize();
bbos.write(b); ByteBuffer bb1 = pool.getBuffer(); ByteBuffer bb = ByteBuffer.wrap(Bytes.toBytes("row123_cf1_q1"));// 13 bytes bbos.write(bb, 0, bb.capacity());
private void allocateNewBuffer() { if (this.curBuf != null) { this.curBuf.flip();// On the current buf set limit = pos and pos = 0. } // Get an initial BB to work with from the pool this.curBuf = this.pool.getBuffer(); if (this.curBuf == null) { // No free BB at this moment. Make a new one. The pool returns off heap BBs. Don't make off // heap BB on demand. It is difficult to account for all such and so proper sizing of Max // direct heap size. See HBASE-15525 also for more details. // Make BB with same size of pool's buffer size. this.curBuf = ByteBuffer.allocate(this.pool.getBufferSize()); } else { this.bufsFromPool.add(this.curBuf); } this.allBufs.add(this.curBuf); }
private void allocateNewBuffer() { if (this.curBuf != null) { this.curBuf.flip();// On the current buf set limit = pos and pos = 0. } // Get an initial BB to work with from the pool this.curBuf = this.pool.getBuffer(); if (this.curBuf == null) { // No free BB at this moment. Make a new one. The pool returns off heap BBs. Don't make off // heap BB on demand. It is difficult to account for all such and so proper sizing of Max // direct heap size. See HBASE-15525 also for more details. // Make BB with same size of pool's buffer size. this.curBuf = ByteBuffer.allocate(this.pool.getBufferSize()); } else { this.bufsFromPool.add(this.curBuf); } this.allBufs.add(this.curBuf); }
private void initPoolWithAllBuffers(ByteBufferPool pool, int maxBuffersInPool) { ByteBuffer[] buffers = new ByteBuffer[maxBuffersInPool]; // Just call getBuffer() on pool 'maxBuffersInPool' so as to init all buffers and then put back // all. Makes pool with max #buffers. for (int i = 0; i < maxBuffersInPool; i++) { buffers[i] = pool.getBuffer(); } for (ByteBuffer buf : buffers) { pool.putbackBuffer(buf); } } }
private void testBBPool(int maxPoolSize, int bufferSize, boolean directByteBuffer) { ByteBufferPool pool = new ByteBufferPool(bufferSize, maxPoolSize, directByteBuffer); for (int i = 0; i < maxPoolSize; i++) { ByteBuffer buffer = pool.getBuffer(); assertEquals(0, buffer.position()); assertEquals(bufferSize, buffer.limit()); assertEquals(directByteBuffer, buffer.isDirect()); } assertEquals(0, pool.getQueueSize()); ByteBuffer bb = directByteBuffer ? ByteBuffer.allocate(bufferSize) : ByteBuffer.allocateDirect(bufferSize); pool.putbackBuffer(bb); assertEquals(0, pool.getQueueSize()); bb = directByteBuffer ? ByteBuffer.allocateDirect(bufferSize + 1) : ByteBuffer.allocate(bufferSize + 1); pool.putbackBuffer(bb); assertEquals(0, pool.getQueueSize()); } }
private void testBBPool(int maxPoolSize, int bufferSize, boolean directByteBuffer) { ByteBufferPool pool = new ByteBufferPool(bufferSize, maxPoolSize, directByteBuffer); for (int i = 0; i < maxPoolSize; i++) { ByteBuffer buffer = pool.getBuffer(); assertEquals(0, buffer.position()); assertEquals(bufferSize, buffer.limit()); assertEquals(directByteBuffer, buffer.isDirect()); } assertEquals(0, pool.getQueueSize()); ByteBuffer bb = directByteBuffer ? ByteBuffer.allocate(bufferSize) : ByteBuffer.allocateDirect(bufferSize); pool.putbackBuffer(bb); assertEquals(0, pool.getQueueSize()); bb = directByteBuffer ? ByteBuffer.allocateDirect(bufferSize + 1) : ByteBuffer.allocate(bufferSize + 1); pool.putbackBuffer(bb); assertEquals(0, pool.getQueueSize()); } }
bbos.write(b); ByteBuffer bb1 = pool.getBuffer(); ByteBuffer bb = ByteBuffer.wrap(Bytes.toBytes("row123_cf1_q1"));// 13 bytes bbos.write(bb, 0, bb.capacity());
bbos.write(b); ByteBuffer bb1 = pool.getBuffer(); ByteBuffer bb = ByteBuffer.wrap(Bytes.toBytes("row123_cf1_q1"));// 13 bytes bbos.write(bb, 0, bb.capacity());