From 4e1356a65867b8f8c396910786728a1ff62035b9 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 19 Feb 2024 13:05:51 +0100 Subject: [PATCH] refactor: Extracted annonymous class into `NoStorageStorageStrategy` -- COPY --- .../nostorage/NoStorageStorageStrategy.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java new file mode 100644 index 00000000..1b20aa37 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java @@ -0,0 +1,53 @@ +package de.juplo.kafka.chat.backend.storage.nostorage; + +import de.juplo.kafka.chat.backend.domain.ChatRoomInfo; +import de.juplo.kafka.chat.backend.domain.Message; +import de.juplo.kafka.chat.backend.implementation.StorageStrategy; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration; +import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import reactor.core.publisher.Flux; + +import java.util.UUID; + + +@ConditionalOnProperty( + prefix = "chat.backend.inmemory", + name = "storage-strategy", + havingValue = "none", + matchIfMissing = true) +@Configuration +@EnableAutoConfiguration( + exclude = { + MongoRepositoriesAutoConfiguration.class, + MongoAutoConfiguration.class }) +public class NoStorageStorageConfiguration +{ + @Bean + public StorageStrategy storageStrategy() + { + return new StorageStrategy() + { + @Override + public void writeChatRoomInfo(Flux chatRoomInfoFlux) {} + + @Override + public Flux readChatRoomInfo() + { + return Flux.empty(); + } + + @Override + public void writeChatRoomData(UUID chatRoomId, Flux messageFlux) {} + + @Override + public Flux readChatRoomData(UUID chatRoomId) + { + return Flux.empty(); + } + }; + } +} -- 2.20.1