共计 2016 个字符,预计需要花费 6 分钟才能阅读完成。
序
本文次要钻研一下 cheddar 的 DomainEvent
DomainEvent
Cheddar/cheddar/cheddar-domain/src/main/java/com/clicktravel/cheddar/domain/event/DomainEvent.java
public interface DomainEvent extends Event {}
DomainEvent 接口继承了 Event 接口
AbstractDomainEvent
Cheddar/cheddar/cheddar-domain/src/main/java/com/clicktravel/cheddar/domain/event/AbstractDomainEvent.java
public abstract class AbstractDomainEvent extends AbstractEvent implements DomainEvent {public abstract String context();
@Override
public final String type() {return context() + "." + getClass().getSimpleName();
}
}
AbstractDomainEvent 继承了 AbstractEvent,申明实现了 DomainEvent 接口,它申明了一个形象的 context 办法
DomainEventHandler
Cheddar/cheddar/cheddar-domain/src/main/java/com/clicktravel/cheddar/domain/event/DomainEventHandler.java
public interface DomainEventHandler extends EventHandler<DomainEvent> {
}
public interface HighPriorityDomainEventHandler extends DomainEventHandler {
}
public interface LowPriorityDomainEventHandler extends DomainEventHandler {}
DomainEventHandler 接口继承了 EventHandler 接口,其泛型为 DomainEvent;HighPriorityDomainEventHandler 及 LowPriorityDomainEventHandler 接口继承了 DomainEventHandler 接口
DomainEventPublisher
Cheddar/cheddar/cheddar-domain/src/main/java/com/clicktravel/cheddar/domain/event/DomainEventPublisher.java
public class DomainEventPublisher extends EventPublisher<DomainEvent> {
private static DomainEventPublisher instance;
public static void init(final MessagePublisher<TypedMessage> messagePublisher) {instance = new DomainEventPublisher(messagePublisher);
}
private DomainEventPublisher(final MessagePublisher<TypedMessage> messagePublisher) {super(messagePublisher);
}
public static DomainEventPublisher instance() {if (instance == null) {throw new IllegalStateException("DomainEventPublisher not initialized");
}
return instance;
}
}
DomainEventPublisher 继承了 EventPublisher,其结构器接管 MessagePublisher;它提供了 init 办法用于创立 DomainEventPublisher,instance 办法用于获取 instance
小结
cheddar 定义了 DomainEvent 接口及 AbstractDomainEvent 抽象类;DomainEventHandler 接口继承了 EventHandler 接口,其泛型为 DomainEvent;DomainEventPublisher 继承了 EventPublisher,其结构器接管 MessagePublisher,其 publishEvent 办法最初通过 MessagePublisher 的 publish 来实现。
doc
- Cheddar