/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size or the timeout expires. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @param timeoutMillis the timeout value in milliseconds, zero or less for no timeout * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize, long timeoutMillis) { return BoundedBuffer.decorate(buffer, maximumSize, timeoutMillis); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size or the timeout expires. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @param timeoutMillis the timeout value in milliseconds, zero or less for no timeout * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize, long timeoutMillis) { return BoundedBuffer.decorate(buffer, maximumSize, timeoutMillis); }
public Object makeObject() { return BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); }
public void testAddAllToEmptyBufferExceedMaxSizeNoTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); try { bounded.addAll(Collections.nCopies(2, "test")); fail(); } catch (BufferOverflowException e) { } }
public void testAddAllToFullBufferNoTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); bounded.add( "Hello" ); try { bounded.addAll(Collections.singleton("World")); fail(); } catch (BufferOverflowException e) { } }
public void testAddToFullBufferNoTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1); bounded.add( "Hello" ); try { bounded.add("World"); fail(); } catch (BufferOverflowException e) { } }
public void testMaxSize() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500); BoundedCollection bc = (BoundedCollection) bounded; assertEquals(2, bc.maxSize()); assertEquals(false, bc.isFull()); bounded.add("A"); assertEquals(false, bc.isFull()); bounded.add("B"); assertEquals(true, bc.isFull()); bounded.remove(); assertEquals(false, bc.isFull()); try { BoundedBuffer.decorate(new UnboundedFifoBuffer(), 0); fail(); } catch (IllegalArgumentException ex) {} try { BoundedBuffer.decorate(new UnboundedFifoBuffer(), -1); fail(); } catch (IllegalArgumentException ex) {} }
public void testAddAllToFullBufferRemoveViaIterator() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500); bounded.add( "Hello" ); bounded.add( "World" ); new DelayedIteratorRemove( bounded, 200, 2 ).start(); bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) ); assertEquals( 2, bounded.size() ); assertEquals( "Foo", bounded.remove() ); assertEquals( "Bar", bounded.remove() ); }
public void testAddToFullBufferRemoveViaIterator() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500); bounded.add( "Hello" ); new DelayedIteratorRemove( bounded, 200 ).start(); bounded.add( "World" ); assertEquals( 1, bounded.size() ); assertEquals( "World", bounded.get() ); }
public void testAddAllToFullBufferWithTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500); bounded.add( "Hello" ); bounded.add( "World" ); new DelayedRemove( bounded, 200, 2 ).start(); bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) ); assertEquals( 2, bounded.size() ); assertEquals( "Foo", bounded.get() ); try { bounded.add( "!" ); fail(); } catch( BufferOverflowException e ) { } }
public void testAddToFullBufferWithTimeout() { final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500); bounded.add( "Hello" ); new DelayedRemove( bounded, 200 ).start(); bounded.add( "World" ); assertEquals( 1, bounded.size() ); assertEquals( "World", bounded.get() ); try { bounded.add( "!" ); fail(); } catch( BufferOverflowException e ) { } }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size or the timeout expires. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @param timeoutMillis the timeout value in milliseconds, zero or less for no timeout * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize, long timeoutMillis) { return BoundedBuffer.decorate(buffer, maximumSize, timeoutMillis); }
/** * Returns a synchronized buffer backed by the given buffer that will * block on {@link Buffer#add(Object)} and * {@link Buffer#addAll(java.util.Collection)} until enough object(s) are * removed from the buffer to allow the object(s) to be added and still * maintain the maximum size or the timeout expires. * * @param buffer the buffer to make bounded, must not be null * @param maximumSize the maximum size * @param timeoutMillis the timeout value in milliseconds, zero or less for no timeout * @return a bounded buffer backed by the given buffer * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ public static Buffer boundedBuffer(Buffer buffer, int maximumSize, long timeoutMillis) { return BoundedBuffer.decorate(buffer, maximumSize, timeoutMillis); }