From 1a14e4f9dfab5e399adf47f70c098e8aafee70e3 Mon Sep 17 00:00:00 2001 From: Bjoern Kieling Date: Thu, 28 Jul 2022 11:58:33 +0200 Subject: [PATCH] GH-27 - Remove in-memory implementation of EventPublicationRepository Signed-off-by: Dmitry Belyaev --- .../config/EventPublicationConfiguration.java | 9 +- .../MapEventPublicationRepository.java | 89 ------------------- 2 files changed, 2 insertions(+), 96 deletions(-) delete mode 100644 spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/MapEventPublicationRepository.java diff --git a/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/config/EventPublicationConfiguration.java b/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/config/EventPublicationConfiguration.java index 23d0665a..89a81a8c 100644 --- a/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/config/EventPublicationConfiguration.java +++ b/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/config/EventPublicationConfiguration.java @@ -16,14 +16,12 @@ package org.springframework.modulith.events.config; import org.springframework.beans.factory.ObjectFactory; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.modulith.events.DefaultEventPublicationRegistry; import org.springframework.modulith.events.EventPublicationRegistry; import org.springframework.modulith.events.EventPublicationRepository; import org.springframework.modulith.events.support.CompletionRegisteringBeanPostProcessor; -import org.springframework.modulith.events.support.MapEventPublicationRepository; import org.springframework.modulith.events.support.PersistentApplicationEventMulticaster; /** @@ -35,11 +33,8 @@ import org.springframework.modulith.events.support.PersistentApplicationEventMul class EventPublicationConfiguration { @Bean - EventPublicationRegistry eventPublicationRegistry( - ObjectProvider repositoryProvider) { - - return new DefaultEventPublicationRegistry( - repositoryProvider.getIfAvailable(MapEventPublicationRepository::new)); + EventPublicationRegistry eventPublicationRegistry(EventPublicationRepository repository) { + return new DefaultEventPublicationRegistry(repository); } @Bean diff --git a/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/MapEventPublicationRepository.java b/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/MapEventPublicationRepository.java deleted file mode 100644 index 17ca06ed..00000000 --- a/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/MapEventPublicationRepository.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2017-2022 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 - * - * http://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.support; - -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; -import lombok.Value; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.TreeMap; - -import org.springframework.modulith.events.CompletableEventPublication; -import org.springframework.modulith.events.EventPublication; -import org.springframework.modulith.events.EventPublicationRepository; -import org.springframework.modulith.events.PublicationTargetIdentifier; - -/** - * Map based {@link EventPublicationRepository}, for testing purposes only. - * - * @author Oliver Drotbohm - * @author Björn Kieling - * @author Dmitry Belyaev - */ -public class MapEventPublicationRepository implements EventPublicationRepository { - - private final Map events = new TreeMap<>(); - - @Override - public EventPublication create(EventPublication publication) { - - return events.computeIfAbsent(Key.of(publication), - it -> CompletableEventPublication.of(it.getEvent(), it.getIdentifier())); - } - - @Override - public EventPublication update(CompletableEventPublication publication) { - - var result = events.computeIfPresent(Key.of(publication), (__, it) -> it.markCompleted()); - - if (result == null) { - throw new IllegalArgumentException("Couldn't find publication %s!".formatted(publication)); - } - - return result; - } - - @Override - public List findIncompletePublications() { - - return events.values().stream() // - .filter(it -> !it.isPublicationCompleted()) - .map(EventPublication.class::cast) - .toList(); - } - - @Override - public Optional findIncompletePublicationsByEventAndTargetIdentifier( - Object event, PublicationTargetIdentifier targetIdentifier) { - - return Optional.ofNullable(events.get(new Key(event, targetIdentifier))); - } - - @Value - @RequiredArgsConstructor(access = AccessLevel.PRIVATE) - private static class Key { - - Object event; - PublicationTargetIdentifier identifier; - - static Key of(EventPublication publication) { - return new Key(publication.getEvent(), publication.getTargetIdentifier()); - } - } -}