@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)); }
monitor.phasedBackoffWithLockStrategy(spinTimeoutNanos, yieldTimeoutNanos); } else { waitStrategy = PhasedBackoffWaitStrategy.withSleep(spinTimeoutNanos, yieldTimeoutNanos, TimeUnit.NANOSECONDS); monitor.phasedBackoffWithSleepStrategy(spinTimeoutNanos, yieldTimeoutNanos);
monitor.phasedBackoffWithLockStrategy(spinTimeoutNanos, yieldTimeoutNanos); } else { waitStrategy = PhasedBackoffWaitStrategy.withSleep(spinTimeoutNanos, yieldTimeoutNanos, TimeUnit.NANOSECONDS); monitor.phasedBackoffWithSleepStrategy(spinTimeoutNanos, yieldTimeoutNanos);
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(); } }