@Test public void acquireAttemptsAreObserved() { PatternStrategy strategy = new RoundRobinLoadBalancer(3, 2); Iterator<Integer> iterator = strategy.nextIndices().iterator(); assertEquals(0, iterator.next().intValue()); assertEquals(1, iterator.next().intValue()); assertFalse(iterator.hasNext()); Iterator<Integer> iterator2 = strategy.nextIndices().iterator(); assertEquals(1, iterator2.next().intValue()); assertEquals(2, iterator2.next().intValue()); assertFalse(iterator2.hasNext()); }
@Override public Iterable<Integer> nextIndices() { long index = counter.getAndIncrement(); if (index >= flipPoint) { resetCounter(index); } SingleReaderArrayIterable iterable = new SingleReaderArrayIterable(maxAcquireAttempts); Integer[] orderToTry = iterable.getIndices(); for (int i = 0; i < maxAcquireAttempts; ++i) { orderToTry[i] = (int) ((index + i) % size); } shuffleTail(orderToTry); return iterable; }
RoundRobinLoadBalancer implements PatternStrategy { @Override public Iterable<Integer> nextIndices() { long index = counter.getAndIncrement(); if (index >= flipPoint) { resetCounter(index); } SingleReaderArrayIterable iterable = new SingleReaderArrayIterable(maxAcquireAttempts); Integer[] orderToTry = iterable.getIndices(); for (int i = 0; i < maxAcquireAttempts; ++i) { orderToTry[i] = (int) ((index + i) % size); } shuffleTail(orderToTry); return iterable; } }
RoundRobinLoadBalancer implements PatternStrategy { @Override public Iterable<Integer> nextIndices() { long index = counter.getAndIncrement(); if (index >= flipPoint) { resetCounter(index); } SingleReaderArrayIterable iterable = new SingleReaderArrayIterable(maxAcquireAttempts); Integer[] orderToTry = iterable.getIndices(); for (int i = 0; i < maxAcquireAttempts; ++i) { orderToTry[i] = (int) ((index + i) % size); } shuffleTail(orderToTry); return iterable; } RoundRobinLoadBalancer(int size);  RoundRobinLoadBalancer(int size, int maxAcquireAttempts);  RoundRobinLoadBalancer(int size, int maxAcquireAttempts, AtomicLong counter); }
RoundRobinLoadBalancer implements PatternStrategy { @Override public Iterable<Integer> nextIndices() { long index = counter.getAndIncrement(); if (index >= flipPoint) { resetCounter(index); } SingleReaderArrayIterable iterable = new SingleReaderArrayIterable(maxAcquireAttempts); Integer[] orderToTry = iterable.getIndices(); for (int i = 0; i < maxAcquireAttempts; ++i) { orderToTry[i] = (int) ((index + i) % size); } shuffleTail(orderToTry); return iterable; } RoundRobinLoadBalancer(int size);  RoundRobinLoadBalancer(int size, int maxAcquireAttempts);  RoundRobinLoadBalancer(int size, int maxAcquireAttempts, AtomicLong counter); @Override Iterable<Integer> nextIndices(); @Override int acquireCount(); }
RoundRobinLoadBalancer implements PatternStrategy { @Override public Iterable<Integer> nextIndices() { long index = counter.getAndIncrement(); if (index >= flipPoint) { resetCounter(index); } SingleReaderArrayIterable iterable = new SingleReaderArrayIterable(maxAcquireAttempts); Integer[] orderToTry = iterable.getIndices(); for (int i = 0; i < maxAcquireAttempts; ++i) { orderToTry[i] = (int) ((index + i) % size); } shuffleTail(orderToTry); return iterable; } RoundRobinLoadBalancer(int size);  RoundRobinLoadBalancer(int size, int maxAcquireAttempts);  RoundRobinLoadBalancer(int size, int maxAcquireAttempts, AtomicLong counter); @Override Iterable<Integer> nextIndices(); @Override int acquireCount();  }