@Test public void shouldHandleSequenceChangeWithTenMillisecondDelay() throws Exception { assertWaitForWithDelayOf(10, PhasedBackoffWaitStrategy.withLock(1, 1, MILLISECONDS)); assertWaitForWithDelayOf(10, PhasedBackoffWaitStrategy.withSleep(1, 1, MILLISECONDS)); } }
@Test public void shouldHandleSequenceChangeWithTwoMillisecondDelay() throws Exception { assertWaitForWithDelayOf(2, PhasedBackoffWaitStrategy.withLock(1, 1, MILLISECONDS)); assertWaitForWithDelayOf(2, PhasedBackoffWaitStrategy.withSleep(1, 1, MILLISECONDS)); }
@Test public void shouldHandleImmediateSequenceChange() throws Exception { assertWaitForWithDelayOf(0, PhasedBackoffWaitStrategy.withLock(1, 1, MILLISECONDS)); assertWaitForWithDelayOf(0, PhasedBackoffWaitStrategy.withSleep(1, 1, MILLISECONDS)); }
@Test public void shouldHandleSequenceChangeWithOneMillisecondDelay() throws Exception { assertWaitForWithDelayOf(1, PhasedBackoffWaitStrategy.withLock(1, 1, MILLISECONDS)); assertWaitForWithDelayOf(1, PhasedBackoffWaitStrategy.withSleep(1, 1, MILLISECONDS)); }
public static DOMNotificationRouter create(final int queueDepth, final long spinTime, final long parkTime, final TimeUnit unit) { Preconditions.checkArgument(Long.lowestOneBit(queueDepth) == Long.highestOneBit(queueDepth), "Queue depth %s is not power-of-two", queueDepth); final ExecutorService executor = Executors.newCachedThreadPool(); final WaitStrategy strategy = PhasedBackoffWaitStrategy.withLock(spinTime, parkTime, unit); return new DOMNotificationRouter(executor, queueDepth, strategy); }
} else if ("backoff".equalsIgnoreCase(strategyType)) { if ("lock".equalsIgnoreCase(phasedBlockingType)) { waitStrategy = PhasedBackoffWaitStrategy.withLock(spinTimeoutNanos, yieldTimeoutNanos, TimeUnit.NANOSECONDS); monitor.phasedBackoffWithLockStrategy(spinTimeoutNanos, yieldTimeoutNanos); } else {
} else if ("backoff".equalsIgnoreCase(strategyType)) { if ("lock".equalsIgnoreCase(phasedBlockingType)) { waitStrategy = PhasedBackoffWaitStrategy.withLock(spinTimeoutNanos, yieldTimeoutNanos, TimeUnit.NANOSECONDS); monitor.phasedBackoffWithLockStrategy(spinTimeoutNanos, yieldTimeoutNanos); } else {
private WaitStrategy createWaitStrategy(RingBufferData data) { switch (data.getWaitStrategy()) { case YIELDING: return new YieldingWaitStrategy(); case SLEEPING: return new SleepingWaitStrategy(); case BACKOFF: if (RingBufferData.PhasedBlockingType.LOCK == data.getPhasedBlockingType()) { return PhasedBackoffWaitStrategy.withLock(data.getSpinTimeoutNanos(), data.getYieldTimeoutNanos(), TimeUnit.NANOSECONDS); } else { return PhasedBackoffWaitStrategy.withSleep(data.getSpinTimeoutNanos(), data.getYieldTimeoutNanos(), TimeUnit.NANOSECONDS); } case SPIN: return new BusySpinWaitStrategy(); case TIMEOUT: return new TimeoutBlockingWaitStrategy(data.getBlockingTimeoutNanos(), TimeUnit.NANOSECONDS); default: return new BlockingWaitStrategy(); } }
private WaitStrategy createWaitStrategy(RingBufferData data) { switch (data.getWaitStrategy()) { case YIELDING: return new YieldingWaitStrategy(); case SLEEPING: return new SleepingWaitStrategy(); case BACKOFF: if (RingBufferData.PhasedBlockingType.LOCK == data.getPhasedBlockingType()) { return PhasedBackoffWaitStrategy.withLock(data.getSpinTimeoutNanos(), data.getYieldTimeoutNanos(), TimeUnit.NANOSECONDS); } else { return PhasedBackoffWaitStrategy.withSleep(data.getSpinTimeoutNanos(), data.getYieldTimeoutNanos(), TimeUnit.NANOSECONDS); } case SPIN: return new BusySpinWaitStrategy(); case TIMEOUT: return new TimeoutBlockingWaitStrategy(data.getBlockingTimeoutNanos(), TimeUnit.NANOSECONDS); default: return new BlockingWaitStrategy(); } }