1、handlerA必须要在handlerB前执行
dw.handleEventsWith(A).then(B);
2、handlerA必须在handlerB前执行
dw.after(A).handleEventsWith(B);
3、举例:注册handler1,handler2,并且配置handlerWithBarrier在handler1,handler2执行完成后执行
disruptor.handleEventsWith(handler1, handler2);
disruptor.after(handler1, handler2).handleEventsWith(handlerWithBarrier);
4、举例:注册handler1,handler2,并且配置handlerWithBarrier在handler1,handler2执行完成后执行。handler1和handler2可以通过and注册到同一个group
disruptor.handleEventsWith(handler1);
final EventHandlerGroup<TestEvent> handler2Group = disruptor.handleEventsWith(handler2);
disruptor.after(handler1).and(handler2Group).handleEventsWith(handlerWithBarrier);
5、举例:调用after配置执行顺序时,需要先通过handleEventsWith注册到Disruptor
@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionIfHandlerIsNotAlreadyConsuming()throws Exception
{
disruptor.after(createDelayedEventHandler()).handleEventsWith(createDelayedEventHandler());
}
6、举例:EvilEqualsEventHandler重写了equals和hashCode方法,下述的handler1和handler2具有相同的equals和hashCode返回值。但是Disruptor内部的handlers的注册时通过IdentityHashMap存储的,也就是根据对象的引用是否相等来判断是否已注册,而非对象是否相等。
@Test(expected = IllegalArgumentException.class)public void shouldTrackEventHandlersByIdentityNotEquality()
throws Exception
{
EvilEqualsEventHandler handler1 = new EvilEqualsEventHandler();
EvilEqualsEventHandler handler2 = new EvilEqualsEventHandler();
disruptor.handleEventsWith(handler1);
disruptor.after(handler2);
}
--->>
java.util.IdentityHashMap<K, V>
This class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values). In other words, in an IdentityHashMap, two keys k1 and k2 are considered equal if and only if (k1==k2). (In normal Map implementations (like HashMap) two keys k1 and k2 are considered equal if and only if (k1==null ? k2==null : k1.equals(k2)).)
大致的意思是该类也是实现了Map接口,但是比较键值时使用reference-equality替代了object-equality比较的方法。只有当k1==k2才被认为是相同键值。普通的实现了Map接口的键值比较相同时是通过k1==null ? k2==null : k1.equals(k2)来确认的。