本文整理汇总了Java中com.lmax.disruptor.Sequence.get方法的典型用法代码示例。如果您正苦于以下问题:Java Sequence.get方法的具体用法?Java Sequence.get怎么用?Java Sequence.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lmax.disruptor.Sequence
的用法示例。
在下文中一共展示了Sequence.get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitFor
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
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;
}
示例2: hasBacklog
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
/**
* Confirms if all messages have been consumed by all event processors
*/
private boolean hasBacklog() {
final long cursor = ringBuffer.getCursor();
for (final Sequence consumer : consumerRepository.getLastSequenceInChain(false)) {
if (cursor > consumer.get()) {
return true;
}
}
return false;
}
示例3: waitFor
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
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;
}
示例4: waitFor
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
@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;
}
示例5: waitFor
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
@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;
}
示例6: waitFor
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public long waitFor(final long sequence, final Sequence cursor,
final Sequence dependentSequence, final SequenceBarrier barrier)
throws AlertException, InterruptedException, TimeoutException {
return cursor.get();
}
示例7: hasBacklog
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
/**
* Confirms if all messages have been consumed by all event processors
*/
private boolean hasBacklog() {
final long cursor = ringBuffer.getCursor();
for (Sequence consumer : consumerRepository.getLastSequenceInChain(false)) {
if (cursor > consumer.get()) {
return true;
}
}
return false;
}
示例8: waitRequestOrTerminalEvent
import com.lmax.disruptor.Sequence; //导入方法依赖的package包/类
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;
}