Skip to content

Commit

Permalink
GH-3 - Refactor events registration to prepare easy addition of new r…
Browse files Browse the repository at this point in the history
…epository types.

- Introduce Repository interface as a customization point
- Get rid of Registry interface by having one generic implementation
- Combine EventPublication and all its subclasses in one domain object
- Make Repository instead of Registry be dependent on EventSerializer

Signed-off-by: Dmitry Belyaev <[email protected]>
  • Loading branch information
Björn Kieling authored and Dmitry Belyaev committed Jul 19, 2022
1 parent 3da6fd9 commit 58ff9bd
Show file tree
Hide file tree
Showing 25 changed files with 514 additions and 631 deletions.
5 changes: 5 additions & 0 deletions .git-authors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
authors:
db: Dmitry Belyaev; dbelyaev
bk: Björn Kieling; bkieling
email:
domain: vmware.com
38 changes: 0 additions & 38 deletions spring-modulith-events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@

<dependencies>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand All @@ -61,24 +41,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
31 changes: 30 additions & 1 deletion spring-modulith-events/spring-modulith-events-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,34 @@
<module.name>org.springframework.modulith.events.core</module.name>
</properties>

<dependencies>

</project>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>

</dependencies>
</project>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,75 +15,95 @@
*/
package org.springframework.modulith.events;

import java.time.Instant;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.PayloadApplicationEvent;
import org.springframework.util.Assert;

import java.time.Instant;

/**
* An event publication.
*
* @author Oliver Drotbohm
* @see CompletableEventPublication#of(Object, PublicationTargetIdentifier)
* @author Oliver Drotbohm, Björn Kieling, Dmitry Belyaev
*/
public interface EventPublication extends Comparable<EventPublication> {
@Data
@Builder
@NoArgsConstructor(force = true)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class EventPublication {

/**
* Returns the event that is published.
*
* @return
* Time the event is published at.
*/
Object getEvent();
private final @NonNull Instant publicationDate;

/**
* Returns the event as Spring {@link ApplicationEvent}, effectively wrapping it into a
* {@link PayloadApplicationEvent} in case it's not one already.
* Identifier of the target that the event is supposed to be published to.
*/
private final @NonNull PublicationTargetIdentifier targetIdentifier;

/**
* Event that is published.
*/
private final @NonNull Object event;

/**
* Completion date of the publication.
*/
private Instant completionDate;

/**
* Marks the event publication as completed.
*
* @return
*/
default ApplicationEvent getApplicationEvent() {

Object event = getEvent();
public EventPublication markCompleted() {

return PayloadApplicationEvent.class.isInstance(event) //
? PayloadApplicationEvent.class.cast(event)
: new PayloadApplicationEvent<>(this, event);
this.completionDate = Instant.now();
return this;
}

/**
* Returns the time the event is published at.
* Returns whether the publication is completed.
*
* @return
*/
Instant getPublicationDate();
public boolean isPublicationCompleted() {
return completionDate != null;
}


/**
* Returns the identifier of the target that the event is supposed to be published to.
* Returns the event as Spring {@link ApplicationEvent}, effectively wrapping it into a
* {@link PayloadApplicationEvent} in case it's not one already.
*
* @return
*/
PublicationTargetIdentifier getTargetIdentifier();
public ApplicationEvent getApplicationEvent() {

Object event = getEvent();

return PayloadApplicationEvent.class.isInstance(event) //
? PayloadApplicationEvent.class.cast(event)
: new PayloadApplicationEvent<>(this, event);
}

/**
* Returns whether the publication is identified by the given {@link PublicationTargetIdentifier}.
*
* @param identifier must not be {@literal null}.
* @return
*/
default boolean isIdentifiedBy(PublicationTargetIdentifier identifier) {
public boolean isIdentifiedBy(PublicationTargetIdentifier identifier) {

Assert.notNull(identifier, "Identifier must not be null!");

return this.getTargetIdentifier().equals(identifier);
}

/*
* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public default int compareTo(EventPublication that) {
return this.getPublicationDate().compareTo(that.getPublicationDate());
}
}
Loading

0 comments on commit 58ff9bd

Please sign in to comment.