sequence

This paper mainly studies the DomainEvent of cheddar

DomainEvent

Cheddar/cheddar/cheddar-domain/src/main/java/com/clicktravel/cheddar/domain/event/DomainEvent.java

public interface DomainEvent extends Event {

}
Copy the code

The DomainEvent interface inherits the Event interface

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(); }}Copy the code

AbstractDomainEvent AbstractEvent AbstractDomainEvent implements the AbstractEvent interface, which declares an abstract context method

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 {

}
Copy the code

The DomainEventHandler interface inherits the EventHandler interface, whose generic type is DomainEvent. HighPriorityDomainEventHandler and LowPriorityDomainEventHandler interface inherits the DomainEventHandler interface

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; }}Copy the code

DomainEventPublisher inherits EventPublisher and its constructor receives MessagePublisher; It provides an init method to create DomainEventPublisher and an instance method to get instance

summary

Cheddar defines the DomainEvent interface and AbstractDomainEvent abstract class. The DomainEventHandler interface inherits the EventHandler interface, whose generic type is DomainEvent. DomainEventPublisher inherits EventPublisher, whose constructor receives MessagePublisher, and whose publishEvent method is finally implemented through the publication of MessagePublisher.

doc

  • Cheddar