public SpscChunkedArrayQueue(int chunkSize, int capacity) { RangeUtil.checkGreaterThanOrEqual(capacity, 16, "capacity"); // minimal chunk size of eight makes sure minimal lookahead step is 2 RangeUtil.checkGreaterThanOrEqual(chunkSize, 8, "chunkSize"); maxQueueCapacity = Pow2.roundToPowerOfTwo(capacity); int chunkCapacity = Pow2.roundToPowerOfTwo(chunkSize); RangeUtil.checkLessThan(chunkCapacity, maxQueueCapacity, "chunkCapacity"); long mask = chunkCapacity - 1; // need extra element to point at next array E[] buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; producerBufferLimit = mask - 1; // we know it's all empty to start with producerQueueLimit = maxQueueCapacity; }
@Override protected int getNextBufferSize(AtomicReferenceArray<E> buffer) { final long maxSize = maxQueueCapacity / 2; RangeUtil.checkLessThanOrEqual(length(buffer), maxSize, "buffer.length"); final int newSize = 2 * (length(buffer) - 1); return newSize + 1; }
@Test(expected = IllegalArgumentException.class) public void checkPositiveMustFailIfArgumentIsLessThanZero() { RangeUtil.checkPositive(-1, "var"); }
public MpmcArrayQueue(final int capacity) { super(RangeUtil.checkGreaterThanOrEqual(capacity, 2, "capacity")); lookAheadStep = Math.max(2, Math.min(capacity() / 4, MAX_LOOK_AHEAD_STEP)); }
/** * Add {@code i} to the set. This is the lower-case '{@code int}' version * of {@link #add} - no autoboxing. Negative values throw * IllegalArgumentException. * @throws IllegalArgumentException if i is negative. * @return <tt>true</tt> if i was added to the set. */ public boolean add( final int i ) { RangeUtil.checkPositiveOrZero(i, "i"); return _nbsi.add(i); } /**
@Test(expected = IllegalArgumentException.class) public void checkLessThanMustFailIfArgumentIsGreaterThanExpected() { RangeUtil.checkLessThan(1, 0, "var"); }
public MpmcAtomicArrayQueue(final int capacity) { super(RangeUtil.checkGreaterThanOrEqual(capacity, 2, "capacity")); lookAheadStep = Math.max(2, Math.min(capacity() / 4, MAX_LOOK_AHEAD_STEP)); }
private final void initialize( int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 if( initial_sz > 1024*1024 ) initial_sz = 1024*1024; for( i=MIN_SIZE_LOG; (1<<i) < (initial_sz<<2); i++ ) ; // Double size for K,V pairs, add 1 for CHM and 1 for hashes _kvs = new Object[((1<<i)<<1)+2]; _kvs[0] = new CHM(new ConcurrentAutoTable()); // CHM in slot 0 _kvs[1] = new int[1<<i]; // Matching hash entries _last_resize_milli = System.currentTimeMillis(); } // Version for subclassed readObject calls, to be called after the defaultReadObject
@Test(expected = IllegalArgumentException.class) public void checkLessThanMustFailIfArgumentIsEqualToExpected() { final int n = 1; final int actual = RangeUtil.checkLessThan(1, 1, "var"); assertThat(actual, is(equalTo(n))); }
public SpscChunkedAtomicArrayQueue(int chunkSize, int capacity) { RangeUtil.checkGreaterThanOrEqual(capacity, 16, "capacity"); // minimal chunk size of eight makes sure minimal lookahead step is 2 RangeUtil.checkGreaterThanOrEqual(chunkSize, 8, "chunkSize"); maxQueueCapacity = Pow2.roundToPowerOfTwo(capacity); int chunkCapacity = Pow2.roundToPowerOfTwo(chunkSize); RangeUtil.checkLessThan(chunkCapacity, maxQueueCapacity, "chunkCapacity"); long mask = chunkCapacity - 1; // need extra element to point at next array AtomicReferenceArray<E> buffer = allocate(chunkCapacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; // we know it's all empty to start with producerBufferLimit = mask - 1; producerQueueLimit = maxQueueCapacity; }
@Test(expected = IllegalArgumentException.class) public void checkGreaterThanOrEqualMustFailIfArgumentIsLessThanExpected() { RangeUtil.checkGreaterThanOrEqual(0, 1, "var"); }
private final void initialize( int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 if( initial_sz > 1024*1024 ) initial_sz = 1024*1024; for( i=MIN_SIZE_LOG; (1<<i) < (initial_sz<<2); i++ ) ; // Double size for K,V pairs, add 1 for CHM and 1 for hashes _kvs = new Object[((1<<i)<<1)+2]; _kvs[0] = new CHM(new ConcurrentAutoTable()); // CHM in slot 0 _kvs[1] = new int[1<<i]; // Matching hash entries _last_resize_milli = System.currentTimeMillis(); } // Version for subclassed readObject calls, to be called after the defaultReadObject
@Test(expected = IllegalArgumentException.class) public void checkPositiveMustFailIfArgumentIsZero() { RangeUtil.checkPositive(0, "var"); }
@Override protected int getNextBufferSize(E[] buffer) { final long maxSize = maxQueueCapacity / 2; RangeUtil.checkLessThanOrEqual(length(buffer), maxSize, "buffer.length"); final int newSize = 2 * (length(buffer) - 1); return newSize + 1; }
@Test public void checkLessThanMustPassIfArgumentIsLessThanExpected() { final int n = 0; final int actual = RangeUtil.checkLessThan(n, 1, "var"); assertThat(actual, is(equalTo(n))); }
MpscChunkedAtomicArrayQueueColdProducerFields(int initialCapacity, int maxCapacity) { super(initialCapacity); RangeUtil.checkGreaterThanOrEqual(maxCapacity, 4, "maxCapacity"); RangeUtil.checkLessThan(roundToPowerOfTwo(initialCapacity), roundToPowerOfTwo(maxCapacity), "initialCapacity"); maxQueueCapacity = ((long) Pow2.roundToPowerOfTwo(maxCapacity)) << 1; } }
/** * @param initialCapacity the queue initial capacity. If chunk size is fixed this will be the chunk size. * Must be 2 or more. */ public BaseMpscLinkedAtomicArrayQueue(final int initialCapacity) { RangeUtil.checkGreaterThanOrEqual(initialCapacity, 2, "initialCapacity"); int p2capacity = Pow2.roundToPowerOfTwo(initialCapacity); // leave lower bit of mask clear long mask = (p2capacity - 1) << 1; // need extra element to point at next array AtomicReferenceArray<E> buffer = allocate(p2capacity + 1); producerBuffer = buffer; producerMask = mask; consumerBuffer = buffer; consumerMask = mask; // we know it's all empty to start with soProducerLimit(mask); }
private void initialize( final int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 for( i=MIN_SIZE_LOG; (1<<i) < initial_sz; i++ ) {/*empty*/} _chm = new CHM(this,new ConcurrentAutoTable(),i); _val_1 = TOMBSTONE; // Always as-if deleted _last_resize_milli = System.currentTimeMillis(); }
@Test public void checkPositiveMustPassIfArgumentIsGreaterThanZero() { final long n = 1; final long actual = RangeUtil.checkPositive(n, "var"); assertThat(actual, is(equalTo(n))); }
@Test(expected = IllegalArgumentException.class) public void checkLessThanOrEqualMustFailIfArgumentIsGreaterThanExpected() { RangeUtil.checkLessThanOrEqual(1, 0, "var"); }