Disruptor - SequenceBarrier

本文深入探讨了SequenceBarrier接口,它是Disruptor框架中的关键组件,用于同步发布者与事件处理器。文章详细介绍了其核心方法,如waitFor、getCursor、isAlerted等,并提及了其未实现方法及其实现类ProcessingSequenceBarrier的构造过程。
  • SequenceBarrier:一个协调屏障,用来跟踪发布者(publisher)的游标(cursor)和事件处理者(EventProcessor)的序列号(sequence)。

 

 long waitFor(long sequence) throws AlertException, InterruptedException, TimeoutException;

 等待给定的序列号可用,用来消费。 

* @throws AlertException       if a status change has occurred for the Disruptor
* @throws InterruptedException if the thread needs awaking on a condition variable.
* @throws TimeoutException     if a timeout occurs while waiting for the supplied sequence.

 long getCursor();

获取当前能读取到的游标(cursor)值。


boolean isAlerted();

barrier当前的状态是否是警报(alert)状态。


void alert();

提醒EventProcessor,一个状态发生了变化,直到清除之前,一直处于这种状态下。


void clearAlert();

清除当前的警报状态。


void checkAlert() throws AlertException;

检查是否提出了警报,如果提出了,就抛出异常。

@throws AlertException if alert has been raised.

 

这个接口提供了几个未实现方法,接下来看下它的实现类 -  ProcessingSequenceBarrier

 

 

(上图是从它的构造器中截取的一部分)

可以看出如果dependentSequence的长度是0,就将cursorSequence指向它,即两者有着相同的引用。

否则,通过FixedSequenceGroup来创建它,即与cursorSequence之间,两者独立存在。

 

 然后重点看下如下几个实现方法:

 

关于Sequencer和WaitStrategy的部分之后的博客中会一一叙述。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值