-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
511 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...nts-api/src/main/java/org/springframework/modulith/events/CompletedEventPublications.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.modulith.events; | ||
|
||
import java.time.Duration; | ||
import java.util.Collection; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* All {@link EventPublication}s that have already been completed. | ||
* | ||
* @author Oliver Drotbohm | ||
* @since 1.1 | ||
*/ | ||
public interface CompletedEventPublications { | ||
|
||
/** | ||
* Returns all {@link EventPublication}s that have already been completed. | ||
* | ||
* @return will never be {@literal null}. | ||
*/ | ||
Collection<? extends EventPublication> findAll(); | ||
|
||
/** | ||
* Deletes all {@link EventPublication}s matching the given {@link Predicate}. Note that implementations will iterate | ||
* all completed {@link EventPublication}s and apply the predicate in memory. | ||
* | ||
* @param filter must not be {@literal null}. | ||
*/ | ||
void deletePublications(Predicate<EventPublication> filter); | ||
|
||
/** | ||
* Deletes all {@link EventPublication}s whose completion date is older than the given {@link Duration}. | ||
* | ||
* @param duration must not be {@literal null}. | ||
*/ | ||
void deletePublicationsOlderThan(Duration duration); | ||
} |
92 changes: 92 additions & 0 deletions
92
...dulith-events-api/src/main/java/org/springframework/modulith/events/EventPublication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.modulith.events; | ||
|
||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.PayloadApplicationEvent; | ||
|
||
/** | ||
* An event publication. | ||
* | ||
* @author Oliver Drotbohm | ||
* @since 1.1 | ||
*/ | ||
public interface EventPublication { | ||
|
||
/** | ||
* Returns a unique identifier for this publication. | ||
* | ||
* @return will never be {@literal null}. | ||
*/ | ||
UUID getIdentifier(); | ||
|
||
/** | ||
* Returns the event that is published. | ||
* | ||
* @return | ||
*/ | ||
Object getEvent(); | ||
|
||
/** | ||
* Returns the event as Spring {@link ApplicationEvent}, effectively wrapping it into a | ||
* {@link PayloadApplicationEvent} in case it's not one already. | ||
* | ||
* @return | ||
*/ | ||
default ApplicationEvent getApplicationEvent() { | ||
|
||
Object event = getEvent(); | ||
|
||
return PayloadApplicationEvent.class.isInstance(event) // | ||
? PayloadApplicationEvent.class.cast(event) | ||
: new PayloadApplicationEvent<>(this, event); | ||
} | ||
|
||
/** | ||
* Returns the time the event is published at. | ||
* | ||
* @return | ||
*/ | ||
Instant getPublicationDate(); | ||
|
||
/** | ||
* Returns the completion date of the publication. | ||
* | ||
* @return will never be {@literal null}. | ||
*/ | ||
Optional<Instant> getCompletionDate(); | ||
|
||
/** | ||
* Returns whether the publication of the event has completed. | ||
* | ||
* @return will never be {@literal null}. | ||
*/ | ||
default boolean isPublicationCompleted() { | ||
return getCompletionDate().isPresent(); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see java.lang.Comparable#compareTo(java.lang.Object) | ||
*/ | ||
default int compareTo(EventPublication that) { | ||
return this.getPublicationDate().compareTo(that.getPublicationDate()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...s-api/src/main/java/org/springframework/modulith/events/UncompletedEventPublications.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.modulith.events; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* @author Oliver Drotbohm | ||
* @since 1.1 | ||
*/ | ||
public interface UncompletedEventPublications { | ||
|
||
void resubmitCompletedPublications(Predicate<EventPublication> filter); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.