领域事件相关建模。
parent
87942d708a
commit
30f67dfa18
|
@ -17,8 +17,8 @@ import lombok.Getter;
|
|||
*/
|
||||
@Getter
|
||||
public abstract class DomainEvent {
|
||||
private String identifier;
|
||||
private long happenedAt;
|
||||
private final String identifier;
|
||||
private final long happenedAt;
|
||||
|
||||
protected DomainEvent() {
|
||||
this.identifier = UUID.randomUUID().toString();
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.Overridable;
|
||||
|
||||
/**
|
||||
* 实体
|
||||
*
|
||||
|
@ -26,7 +28,29 @@ public abstract class Entity<ID extends Serializable> {
|
|||
|
||||
public abstract Optional<ID> getId();
|
||||
|
||||
protected void addDomainEvent(DomainEvent domainEvent) {
|
||||
protected final void addDomainEvent(DomainEvent domainEvent) {
|
||||
domainEvents.add(domainEvent);
|
||||
}
|
||||
|
||||
public final List<DomainEvent> getDomainEvents() {
|
||||
return List.copyOf(domainEvents);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Overridable
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Overridable
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Overridable
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package xyz.zhouxy.plusone.domain;
|
||||
|
||||
public interface IDomainEventPublisher {
|
||||
|
||||
void publish(DomainEvent domainEvent);
|
||||
|
||||
<T extends DomainEvent> void subsrcibe(IDomainEventSubscriber<T> subscriber);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package xyz.zhouxy.plusone.domain;
|
||||
|
||||
/**
|
||||
* 领域事件消费者
|
||||
*/
|
||||
public interface IDomainEventSubscriber<T extends DomainEvent> {
|
||||
|
||||
void handleEvent(final T event);
|
||||
|
||||
Class<T> subscribedToEventType();
|
||||
}
|
Loading…
Reference in New Issue