From: <mar...@us...> - 2011-06-09 15:01:17
|
Revision: 4653 http://bigdata.svn.sourceforge.net/bigdata/?rev=4653&view=rev Author: martyncutcher Date: 2011-06-09 15:01:10 +0000 (Thu, 09 Jun 2011) Log Message: ----------- make release methods private on DirectBufferPool Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPool.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPoolAllocator.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPool.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPoolAllocator.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPool.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPool.java 2011-06-09 14:38:02 UTC (rev 4652) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPool.java 2011-06-09 15:01:10 UTC (rev 4653) @@ -165,7 +165,6 @@ * native memory. */ final private BlockingQueue<ByteBuffer> pool; - final private ArrayList<ByteBuffer> acquiredBuffers; /** * The number {@link ByteBuffer}s allocated (must use {@link #lock} for @@ -437,8 +436,6 @@ this.pool = new LinkedBlockingQueue<ByteBuffer>(poolCapacity); - this.acquiredBuffers = new ArrayList<ByteBuffer>(); - pools.add(this); } @@ -519,7 +516,6 @@ // the head of the pool must exist. final ByteBuffer buf = pool.take(); - acquiredBuffers.add(buf); acquired++; totalAcquireCount.increment(); @@ -558,7 +554,7 @@ * if the buffer has already been released. * @throws InterruptedException */ - final protected void release(final ByteBuffer b) throws InterruptedException { + final private void release(final ByteBuffer b) throws InterruptedException { if (!release(b, Long.MAX_VALUE, TimeUnit.MILLISECONDS)) { @@ -596,10 +592,6 @@ try { // add to the pool. - if (!acquiredBuffers.contains(b)) - throw new IllegalArgumentException("Buffer not managed by this pool or already released"); - acquiredBuffers.remove(b); - if(!pool.offer(b, timeout, units)) return false; Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPoolAllocator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPoolAllocator.java 2011-06-09 14:38:02 UTC (rev 4652) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/io/DirectBufferPoolAllocator.java 2011-06-09 15:01:10 UTC (rev 4653) @@ -293,7 +293,7 @@ * released. */ // Note: package private for the unit tests. - final /*private*/ ByteBuffer nativeBuffer; + final /*private*/ IBufferAccess nativeBuffer; /** * A {@link ByteBuffer#slice()} onto the allocated region of the @@ -325,7 +325,7 @@ } private Allocation(final AllocationContext allocationContext, - final ByteBuffer nativeBuffer, final ByteBuffer allocatedSlice) { + final IBufferAccess nativeBuffer, final ByteBuffer allocatedSlice) { if (allocationContext == null) throw new IllegalArgumentException(); @@ -465,7 +465,7 @@ nativeBuffer.limit(limit); // create the slice. - final Allocation a = new Allocation(this, nativeBuffer, + final Allocation a = new Allocation(this, directBuffer, nativeBuffer.slice()); // restore limit to the remaining capacity. Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPool.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPool.java 2011-06-09 14:38:02 UTC (rev 4652) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPool.java 2011-06-09 15:01:10 UTC (rev 4653) @@ -175,33 +175,4 @@ } - /** - * Unit test to verify that a pool will reject a buffer not acquired from - * that pool. - */ - public void test_rejectBufferFromAnotherPool() throws InterruptedException { - - // A distinct pool with the same buffer capacity - final DirectBufferPool testPool = new DirectBufferPool("test", - 1/* poolCapacity */, DirectBufferPool.INSTANCE - .getBufferCapacity()); - - IBufferAccess b = null; - try { - b = DirectBufferPool.INSTANCE.acquire(); - try { - // Only possible to test since in same package - testPool.release(b.buffer()); - fail("Release should not be permitted to a different pool. Expecting: " - + IllegalArgumentException.class); - } catch (IllegalArgumentException ex) { - if (log.isInfoEnabled()) - log.info("Ignoring expected exception: " + ex); - } - } finally { - b.release(); - } - - } - } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPoolAllocator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPoolAllocator.java 2011-06-09 14:38:02 UTC (rev 4652) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/io/TestDirectBufferPoolAllocator.java 2011-06-09 15:01:10 UTC (rev 4653) @@ -230,10 +230,10 @@ assertTrue(x0.nativeBuffer == x1.nativeBuffer); // the position was advanced by the #of bytes allocated. - assertEquals(allocSize * 2, x0.nativeBuffer.position()); + assertEquals(allocSize * 2, x0.nativeBuffer.buffer().position()); // the limit on the native byte buffer has not been changed. - assertEquals(x0.nativeBuffer.capacity(), x0.nativeBuffer.limit()); + assertEquals(x0.nativeBuffer.buffer().capacity(), x0.nativeBuffer.buffer().limit()); } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |