/** * Release the resources it uses (The ByteBuffers) which are obtained from pool. Call this only * when all the data is fully used. And it must be called at the end of usage else we will leak * ByteBuffers from pool. */ public void releaseResources() { try { close(); } catch (IOException e) { LOG.debug(e.toString(), e); } // Return back all the BBs to pool if (this.bufsFromPool != null) { for (int i = 0; i < this.bufsFromPool.size(); i++) { this.pool.putbackBuffer(this.bufsFromPool.get(i)); } this.bufsFromPool = null; } this.allBufs = null; this.curBuf = null; }
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); } } }
pool.putbackBuffer(bufsFromPoolFinal[i]);
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()); } }
ByteBuffer bb = ByteBuffer.wrap(Bytes.toBytes("row123_cf1_q1"));// 13 bytes bbos.write(bb, 0, bb.capacity()); pool.putbackBuffer(bb1); bbos.writeInt(123); bbos.writeInt(124);
/** * Release the resources it uses (The ByteBuffers) which are obtained from pool. Call this only * when all the data is fully used. And it must be called at the end of usage else we will leak * ByteBuffers from pool. */ public void releaseResources() { try { close(); } catch (IOException e) { LOG.debug(e.toString(), e); } // Return back all the BBs to pool if (this.bufsFromPool != null) { for (int i = 0; i < this.bufsFromPool.size(); i++) { this.pool.putbackBuffer(this.bufsFromPool.get(i)); } this.bufsFromPool = null; } this.allBufs = null; this.curBuf = null; }
/** * Release the resources it uses (The ByteBuffers) which are obtained from pool. Call this only * when all the data is fully used. And it must be called at the end of usage else we will leak * ByteBuffers from pool. */ public void releaseResources() { try { close(); } catch (IOException e) { LOG.debug(e.toString(), e); } // Return back all the BBs to pool if (this.bufsFromPool != null) { for (int i = 0; i < this.bufsFromPool.size(); i++) { this.pool.putbackBuffer(this.bufsFromPool.get(i)); } this.bufsFromPool = null; } this.allBufs = null; this.curBuf = null; }
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()); } }
ByteBuffer bb = ByteBuffer.wrap(Bytes.toBytes("row123_cf1_q1"));// 13 bytes bbos.write(bb, 0, bb.capacity()); pool.putbackBuffer(bb1); bbos.writeInt(123); bbos.writeInt(124);
ByteBuffer bb = ByteBuffer.wrap(Bytes.toBytes("row123_cf1_q1"));// 13 bytes bbos.write(bb, 0, bb.capacity()); pool.putbackBuffer(bb1); bbos.writeInt(123); bbos.writeInt(124);