Java Code Examples for com.lmax.disruptor.SequenceBarrier#checkAlert()
The following examples show how to use
com.lmax.disruptor.SequenceBarrier#checkAlert() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SleepWaitStrategyFactory.java From fastjgame with Apache License 2.0 | 6 votes |
private int applyWaitMethod(final SequenceBarrier barrier, int counter) throws AlertException { // 检查中断/终止信号 barrier.checkAlert(); if (counter > 100) { // 大于100时自旋 --counter; } else if (counter > 0) { // 大于0时尝试让出Cpu --counter; Thread.yield(); } else { // 等到最大次数了,睡眠等待 LockSupport.parkNanos(sleepTimeNs); } return counter; }
Example 2
Source File: BusySpinWaitStrategyFactory.java From fastjgame with Apache License 2.0 | 6 votes |
@Override public long waitFor(final long sequence, Sequence cursor, final Sequence dependentSequence, final SequenceBarrier barrier) throws AlertException, InterruptedException { long availableSequence; int spinTries = 0; // dependentSequence 该项目组织架构中,其实只是生产者的sequence,也就是cursor while ((availableSequence = dependentSequence.get()) < sequence) { barrier.checkAlert(); Thread.onSpinWait(); if (++spinTries == loopOnceSpinTries) { spinTries = 0; eventLoop.safeLoopOnce(); } } return availableSequence; }
Example 3
Source File: SleepingBlockingWaitStrategy.java From ballerina-message-broker with Apache License 2.0 | 6 votes |
public long waitFor(long sequence, Sequence cursorSequence, Sequence dependentSequence, SequenceBarrier barrier) throws AlertException, InterruptedException { if (cursorSequence.get() < sequence) { this.lock.lock(); try { while (cursorSequence.get() < sequence) { barrier.checkAlert(); this.processorNotifyCondition.await(); } } finally { this.lock.unlock(); } } long availableSequence; while ((availableSequence = dependentSequence.get()) < sequence) { barrier.checkAlert(); LockSupport.parkNanos(1L); } return availableSequence; }
Example 4
Source File: YieldWaitStrategyFactory.java From fastjgame with Apache License 2.0 | 5 votes |
private int applyWaitMethod(final SequenceBarrier barrier, int counter) throws AlertException { // 检查中断、停止信号 barrier.checkAlert(); if (counter > 0) { --counter; } else { Thread.yield(); } return counter; }
Example 5
Source File: ExponentionallyIncreasingSleepingWaitStrategy.java From apm-agent-java with Apache License 2.0 | 5 votes |
private int applyWaitMethod(final SequenceBarrier barrier, int currentSleep) throws AlertException { barrier.checkAlert(); if (currentSleep < sleepTimeNsMax) { LockSupport.parkNanos(currentSleep); return currentSleep * 2; } else { LockSupport.parkNanos(sleepTimeNsMax); return currentSleep; } }
Example 6
Source File: LoggerServiceImpl.java From gflogger with Apache License 2.0 | 5 votes |
public long waitFor( long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier ) throws AlertException, InterruptedException, TimeoutException { long availableSequence; if ((availableSequence = cursor.get()) < sequence) { flush(); synchronized (lock) { ++numWaiters; while ((availableSequence = cursor.get()) < sequence) { if (state == State.STOPPED) { disruptor.halt(); throw AlertException.INSTANCE; } barrier.checkAlert(); //*/ lock.wait(); /*/ Thread.sleep(1); //*/ } --numWaiters; } } while ((availableSequence = dependentSequence.get()) < sequence) { barrier.checkAlert(); } return availableSequence; }
Example 7
Source File: ParkWaitStrategy.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
@Override public long waitFor(long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier) throws AlertException, InterruptedException, TimeoutException { long availableSequence; while ((availableSequence = dependentSequence.get()) < sequence) { barrier.checkAlert(); LockSupport.parkNanos(parkFor); } return availableSequence; }
Example 8
Source File: SpinLoopHintBusySpinWaitStrategy.java From perf-workshop with Apache License 2.0 | 5 votes |
@Override public long waitFor(final long sequence, Sequence cursor, final Sequence dependentSequence, final SequenceBarrier barrier) throws AlertException, InterruptedException { long availableSequence; while ((availableSequence = dependentSequence.get()) < sequence) { SpinHint.spinLoopHint(); barrier.checkAlert(); } return availableSequence; }
Example 9
Source File: RingBufferSubscriberUtils.java From camunda-bpm-reactor with Apache License 2.0 | 4 votes |
public static <T> boolean waitRequestOrTerminalEvent( Sequence pendingRequest, RingBuffer<MutableSignal<T>> ringBuffer, SequenceBarrier barrier, Subscriber<? super T> subscriber, AtomicBoolean isRunning ) { final long waitedSequence = ringBuffer.getCursor() + 1L; try { MutableSignal<T> event = null; while (pendingRequest.get() < 0l) { //pause until first request if (event == null) { barrier.waitFor(waitedSequence); event = ringBuffer.get(waitedSequence); if (event.type == MutableSignal.Type.COMPLETE) { try { subscriber.onComplete(); return false; } catch (Throwable t) { Exceptions.throwIfFatal(t); subscriber.onError(t); return false; } } else if (event.type == MutableSignal.Type.ERROR) { subscriber.onError(event.error); return false; } } else { barrier.checkAlert(); } LockSupport.parkNanos(1l); } } catch (TimeoutException te) { //ignore } catch (AlertException ae) { if (!isRunning.get()) { return false; } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } return true; }