diff --git a/cms-api/src/main/java/com/condation/cms/api/annotations/FeatureScope.java b/cms-api/src/main/java/com/condation/cms/api/annotations/FeatureScope.java index edecef4bb..650ab8f2f 100644 --- a/cms-api/src/main/java/com/condation/cms/api/annotations/FeatureScope.java +++ b/cms-api/src/main/java/com/condation/cms/api/annotations/FeatureScope.java @@ -23,6 +23,7 @@ */ +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -32,6 +33,7 @@ * * @author t.marx */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE }) public @interface FeatureScope { diff --git a/cms-api/src/main/java/com/condation/cms/api/configuration/ConfigurationManagement.java b/cms-api/src/main/java/com/condation/cms/api/configuration/ConfigurationManagement.java index 22507fd2f..898424d29 100644 --- a/cms-api/src/main/java/com/condation/cms/api/configuration/ConfigurationManagement.java +++ b/cms-api/src/main/java/com/condation/cms/api/configuration/ConfigurationManagement.java @@ -31,7 +31,6 @@ import com.condation.cms.api.eventbus.events.ConfigurationFileChanged; import com.condation.cms.api.scheduler.CronJobContext; import com.condation.cms.api.scheduler.CronJobScheduler; -import com.google.inject.Inject; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -48,8 +47,7 @@ * @author t.marx */ @Slf4j -@RequiredArgsConstructor(onConstructor = @__({ - @Inject})) +@RequiredArgsConstructor public class ConfigurationManagement { final DB db; diff --git a/cms-api/src/main/java/com/condation/cms/api/eventbus/EventBus.java b/cms-api/src/main/java/com/condation/cms/api/eventbus/EventBus.java index c082913f6..77ac6cfab 100644 --- a/cms-api/src/main/java/com/condation/cms/api/eventbus/EventBus.java +++ b/cms-api/src/main/java/com/condation/cms/api/eventbus/EventBus.java @@ -34,8 +34,4 @@ public interface EventBus { void publish(final T event); void register(Class eventClass, EventListener listener); - - public void unregister(Class eventClass, EventListener listener); - - public void unregister(EventListener listener); } diff --git a/cms-api/src/main/java/com/condation/cms/api/feature/features/MessagingFeature.java b/cms-api/src/main/java/com/condation/cms/api/feature/features/MessagingFeature.java new file mode 100644 index 000000000..1da73181e --- /dev/null +++ b/cms-api/src/main/java/com/condation/cms/api/feature/features/MessagingFeature.java @@ -0,0 +1,35 @@ +package com.condation.cms.api.feature.features; + +/*- + * #%L + * cms-api + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.condation.cms.api.annotations.FeatureScope; +import com.condation.cms.api.feature.Feature; +import com.condation.cms.api.messaging.Messaging; + +/** + * + * @author t.marx + */ +@FeatureScope({FeatureScope.Scope.GLOBAL, FeatureScope.Scope.MODULE}) +public record MessagingFeature(Messaging messaging) implements Feature { +} diff --git a/cms-api/src/main/java/com/condation/cms/api/mapper/ContentNodeMapper.java b/cms-api/src/main/java/com/condation/cms/api/mapper/ContentNodeMapper.java index e2198bd2c..5e0b37205 100644 --- a/cms-api/src/main/java/com/condation/cms/api/mapper/ContentNodeMapper.java +++ b/cms-api/src/main/java/com/condation/cms/api/mapper/ContentNodeMapper.java @@ -42,8 +42,7 @@ * * @author t.marx */ -@RequiredArgsConstructor(onConstructor = @__({ - @Inject})) +@RequiredArgsConstructor() @Slf4j public class ContentNodeMapper { diff --git a/cms-api/src/main/java/com/condation/cms/api/messaging/Listener.java b/cms-api/src/main/java/com/condation/cms/api/messaging/Listener.java new file mode 100644 index 000000000..d958a81ec --- /dev/null +++ b/cms-api/src/main/java/com/condation/cms/api/messaging/Listener.java @@ -0,0 +1,31 @@ +package com.condation.cms.api.messaging; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +/** + * + * @author t.marx + */ +public interface Listener { + void receive (T data); +} diff --git a/cms-api/src/main/java/com/condation/cms/api/messaging/Messaging.java b/cms-api/src/main/java/com/condation/cms/api/messaging/Messaging.java new file mode 100644 index 000000000..67dc16ee7 --- /dev/null +++ b/cms-api/src/main/java/com/condation/cms/api/messaging/Messaging.java @@ -0,0 +1,35 @@ +package com.condation.cms.api.messaging; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +/** + * + * Messaging is a framework for communication between modules and cms components. + * Objects are serialized to json and deserialized to overcome the classloader. + * + * @author t.marx + */ +public interface Messaging { + + Topic topic (String name); +} diff --git a/cms-api/src/main/java/com/condation/cms/api/messaging/Topic.java b/cms-api/src/main/java/com/condation/cms/api/messaging/Topic.java new file mode 100644 index 000000000..646bfc99d --- /dev/null +++ b/cms-api/src/main/java/com/condation/cms/api/messaging/Topic.java @@ -0,0 +1,60 @@ +package com.condation.cms.api.messaging; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +/** + * + * @author t.marx + */ +public interface Topic { + + public static enum Mode { + ASYNC, SYNC; + } + + /** + * Subscribe to a topic. + * + * @param + * @param listener + * @param dataType + */ + void subscribe(Listener listener, Class dataType); + + /** + * Publish a message on the topic with mode. + * + * @param object + * @param mode + */ + void publish(Object object, Mode mode); + + /** + * Publish a message on the topic with default mode: Mode.ASYNC + * + * @param object + */ + default void publish (Object object) { + publish(object, Topic.Mode.ASYNC); + } +} diff --git a/cms-core/pom.xml b/cms-core/pom.xml index 85464d9b4..b0a164128 100644 --- a/cms-core/pom.xml +++ b/cms-core/pom.xml @@ -14,6 +14,10 @@ com.condation.cms cms-api + + com.google.code.gson + gson + org.projectlombok lombok diff --git a/cms-core/src/main/java/com/condation/cms/core/eventbus/DefaultEventBus.java b/cms-core/src/main/java/com/condation/cms/core/eventbus/DefaultEventBus.java index c9fb8b2d0..3072f9112 100644 --- a/cms-core/src/main/java/com/condation/cms/core/eventbus/DefaultEventBus.java +++ b/cms-core/src/main/java/com/condation/cms/core/eventbus/DefaultEventBus.java @@ -50,17 +50,6 @@ private Multimap, EventListener> listeners () { public void register(Class eventClass, EventListener listener) { listeners.put(eventClass, listener); } - - @Override - public void unregister(Class eventClass, EventListener listener) { - if (listeners.containsKey(eventClass)) { - listeners.get(eventClass).remove(listener); - } - } - @Override - public void unregister(EventListener listener) { - listeners().keySet().forEach(eventClass -> unregister(eventClass, listener)); - } @Override public void publish(final T event) { diff --git a/cms-core/src/main/java/com/condation/cms/core/eventbus/MessagingEventBus.java b/cms-core/src/main/java/com/condation/cms/core/eventbus/MessagingEventBus.java new file mode 100644 index 000000000..e765102b7 --- /dev/null +++ b/cms-core/src/main/java/com/condation/cms/core/eventbus/MessagingEventBus.java @@ -0,0 +1,62 @@ +package com.condation.cms.core.eventbus; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.condation.cms.api.eventbus.Event; +import com.condation.cms.api.eventbus.EventBus; +import com.condation.cms.api.eventbus.EventListener; +import com.condation.cms.api.messaging.Messaging; +import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; + +/** + * + * @author t.marx + */ +@Slf4j +public class MessagingEventBus implements EventBus { + + private final Messaging messaging; + + @Inject + public MessagingEventBus(final Messaging messaging) { + this.messaging = messaging; + } + + @Override + public void register(Class eventClass, EventListener listener) { + messaging.topic(eventClass.getName()).subscribe((data) -> { + listener.consum(data); + }, eventClass); + } + + @Override + public void publish(final T event) { + messaging.topic(event.getClass().getName()).publish(event); + } + + @Override + public void syncPublish(T event) { + publish(event); + } +} diff --git a/cms-core/src/main/java/com/condation/cms/core/messaging/DefaultMessaging.java b/cms-core/src/main/java/com/condation/cms/core/messaging/DefaultMessaging.java new file mode 100644 index 000000000..ddcd19325 --- /dev/null +++ b/cms-core/src/main/java/com/condation/cms/core/messaging/DefaultMessaging.java @@ -0,0 +1,67 @@ +package com.condation.cms.core.messaging; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.condation.cms.api.messaging.Topic; +import com.condation.cms.api.messaging.Messaging; +import com.condation.cms.api.eventbus.Event; +import com.condation.cms.api.eventbus.EventListener; +import com.condation.cms.core.messaging.converters.PathConverter; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.inject.Inject; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author t.marx + */ +public class DefaultMessaging implements Messaging { + + static final Gson GSON; + static { + GSON = new GsonBuilder() + .registerTypeHierarchyAdapter(Path.class, new PathConverter()) + .enableComplexMapKeySerialization() + .create(); + } + + public final Multimap, EventListener> listeners; + + Map topics; + + @Inject + public DefaultMessaging () { + listeners = ArrayListMultimap.create(); + topics = new HashMap<>(); + } + + @Override + public Topic topic(String name) { + return topics.computeIfAbsent(name, (topic) -> new DefaultTopic(topic)); + } +} diff --git a/cms-core/src/main/java/com/condation/cms/core/messaging/DefaultTopic.java b/cms-core/src/main/java/com/condation/cms/core/messaging/DefaultTopic.java new file mode 100644 index 000000000..eddcf1f51 --- /dev/null +++ b/cms-core/src/main/java/com/condation/cms/core/messaging/DefaultTopic.java @@ -0,0 +1,81 @@ +package com.condation.cms.core.messaging; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ +import com.condation.cms.api.messaging.Topic; +import com.condation.cms.api.messaging.Listener; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import lombok.extern.slf4j.Slf4j; + +/** + * + * @author t.marx + */ +@Slf4j +public final class DefaultTopic implements Topic { + + private final List listeners; + + String name; + + record ListenerHolder(Listener listener, Class dataType) { + + } + + ; + + protected DefaultTopic(String name) { + this.name = name; + listeners = new ArrayList<>(); + } + + @Override + public void subscribe(Listener listener, Class dataType) { + listeners.add(new ListenerHolder<>(listener, dataType)); + } + + @Override + public void publish(final Object data, Mode mode) { + + listeners.forEach((listener) -> { + if (Mode.SYNC.equals(mode)) { + sendMessage(data, listener); + } else { + Thread.startVirtualThread(() -> { + sendMessage(data, listener); + }); + } + }); + } + + private void sendMessage(final Object data, ListenerHolder listener) { + try { + String dataString = DefaultMessaging.GSON.toJson(data); + Object payload = DefaultMessaging.GSON.fromJson(dataString, listener.dataType); + listener.listener.receive(payload); + } catch (Exception e) { + log.error(null, e); + } + } +} diff --git a/cms-core/src/main/java/com/condation/cms/core/messaging/converters/PathConverter.java b/cms-core/src/main/java/com/condation/cms/core/messaging/converters/PathConverter.java new file mode 100644 index 000000000..39af664dc --- /dev/null +++ b/cms-core/src/main/java/com/condation/cms/core/messaging/converters/PathConverter.java @@ -0,0 +1,51 @@ +package com.condation.cms.core.messaging.converters; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * + * @author t.marx + */ +public class PathConverter implements JsonDeserializer, JsonSerializer { + + @Override + public Path deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + return Paths.get(jsonElement.getAsString()); + } + + @Override + public JsonElement serialize(Path path, Type type, JsonSerializationContext jsonSerializationContext) { + return new JsonPrimitive(path.toString()); + } +} diff --git a/cms-server/src/test/java/com/condation/cms/eventbus/DefaultEventBusTest.java b/cms-core/src/test/java/com/condation/cms/core/eventbus/DefaultEventBusTest.java similarity index 64% rename from cms-server/src/test/java/com/condation/cms/eventbus/DefaultEventBusTest.java rename to cms-core/src/test/java/com/condation/cms/core/eventbus/DefaultEventBusTest.java index 3459af929..a4130fe45 100644 --- a/cms-server/src/test/java/com/condation/cms/eventbus/DefaultEventBusTest.java +++ b/cms-core/src/test/java/com/condation/cms/core/eventbus/DefaultEventBusTest.java @@ -1,4 +1,4 @@ -package com.condation.cms.eventbus; +package com.condation.cms.core.eventbus; /*- * #%L @@ -27,7 +27,6 @@ import com.condation.cms.api.eventbus.EventBus; import com.condation.cms.api.eventbus.EventListener; import com.condation.cms.api.eventbus.events.GenericEvent; -import com.condation.cms.core.eventbus.DefaultEventBus; import java.time.Duration; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -49,7 +48,7 @@ public void setup () { } @Test - public void register_unregister_event() { + public void register_event() { var genericEvent = new GenericEvent("bla", Map.of("message", "Hello world!")); var testListener = new TestListener(); @@ -60,40 +59,6 @@ public void register_unregister_event() { Awaitility.await().atMost(Duration.ofSeconds(2)).until(() -> testListener.counter.get() == 1 ); - - eventBus.unregister(GenericEvent.class, testListener); - - eventBus.publish(genericEvent); - - Awaitility.await().atLeast(Duration.ofSeconds(2)); - - Awaitility.await().atMost(Duration.ofSeconds(2)).until(() -> - testListener.counter.get() == 1 - ); - } - - @Test - public void register_unregister_listener() { - var genericEvent = new GenericEvent("bla", Map.of("message", "Hello world!")); - var testListener = new TestListener(); - - eventBus.register(GenericEvent.class, testListener); - - eventBus.publish(genericEvent); - - Awaitility.await().atMost(Duration.ofSeconds(2)).until(() -> - testListener.counter.get() == 1 - ); - - eventBus.unregister(testListener); - - eventBus.publish(genericEvent); - - Awaitility.await().atLeast(Duration.ofSeconds(2)); - - Awaitility.await().atMost(Duration.ofSeconds(2)).until(() -> - testListener.counter.get() == 1 - ); } public static class TestListener implements EventListener { diff --git a/cms-core/src/test/java/com/condation/cms/core/eventbus/MessagingEventBusTest.java b/cms-core/src/test/java/com/condation/cms/core/eventbus/MessagingEventBusTest.java new file mode 100644 index 000000000..b82f3213b --- /dev/null +++ b/cms-core/src/test/java/com/condation/cms/core/eventbus/MessagingEventBusTest.java @@ -0,0 +1,76 @@ +package com.condation.cms.core.eventbus; + +/*- + * #%L + * cms-server + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + + + +import com.condation.cms.api.eventbus.EventBus; +import com.condation.cms.api.eventbus.EventListener; +import com.condation.cms.api.eventbus.events.GenericEvent; +import com.condation.cms.core.messaging.DefaultMessaging; +import com.condation.cms.api.messaging.Messaging; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * + * @author t.marx + */ +public class MessagingEventBusTest { + + EventBus eventBus; + Messaging messaging; + + @BeforeEach + public void setup () { + messaging = new DefaultMessaging(); + eventBus = new MessagingEventBus(messaging); + } + + @Test + public void register_event() { + var genericEvent = new GenericEvent("bla", Map.of("message", "Hello world!")); + var testListener = new TestListener(); + + eventBus.register(GenericEvent.class, testListener); + + eventBus.publish(genericEvent); + + Awaitility.await().atMost(Duration.ofSeconds(2)).until(() -> + testListener.counter.get() == 1 + ); + } + + public static class TestListener implements EventListener { + + AtomicInteger counter = new AtomicInteger(0); + @Override + public void consum(GenericEvent event) { + counter.incrementAndGet(); + } + } +} diff --git a/cms-core/src/test/java/com/condation/cms/core/messaging/DefaultMessagingTest.java b/cms-core/src/test/java/com/condation/cms/core/messaging/DefaultMessagingTest.java new file mode 100644 index 000000000..804e4f9db --- /dev/null +++ b/cms-core/src/test/java/com/condation/cms/core/messaging/DefaultMessagingTest.java @@ -0,0 +1,64 @@ +package com.condation.cms.core.messaging; + +/*- + * #%L + * cms-core + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ + +import com.condation.cms.api.messaging.Messaging; +import com.condation.cms.api.messaging.Topic; +import java.time.Duration; +import java.util.concurrent.atomic.AtomicBoolean; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * + * @author t.marx + */ +public class DefaultMessagingTest { + + Messaging messaging; + + @BeforeEach + void setup () { + messaging = new DefaultMessaging(); + } + + @Test + public void testSomeMethod() { + + AtomicBoolean received = new AtomicBoolean(false); + messaging.topic("test/test").subscribe((data) -> { + System.out.println(data.value); + received.set(true); + }, AnotherObject.class); + + messaging.topic("test/test").publish(new DataObject("Hello CondationCMS!"), Topic.Mode.SYNC); + + Awaitility.await() + .atMost(Duration.ofSeconds(1)) + .until(received::get); + } + + public static record DataObject (String value){} + public static record AnotherObject (String value){} +} diff --git a/cms-server/hosts/features/site.yaml b/cms-server/hosts/features/site.yaml index c42eb0216..bd10e799f 100644 --- a/cms-server/hosts/features/site.yaml +++ b/cms-server/hosts/features/site.yaml @@ -3,7 +3,7 @@ hostname: - localhost2 baseurl: "http://localhost2:1010" language: en -test: Hallo +test: Hallo12 theme: test cache: content: true diff --git a/cms-server/src/main/java/com/condation/cms/server/JettyServer.java b/cms-server/src/main/java/com/condation/cms/server/JettyServer.java index 766316a51..35b8235ec 100644 --- a/cms-server/src/main/java/com/condation/cms/server/JettyServer.java +++ b/cms-server/src/main/java/com/condation/cms/server/JettyServer.java @@ -26,7 +26,6 @@ import com.condation.cms.api.Constants; import com.condation.cms.api.ServerProperties; import com.condation.cms.api.configuration.Configuration; -import com.condation.cms.api.configuration.ConfigurationManagement; import com.condation.cms.api.configuration.configs.ServerConfiguration; import com.condation.cms.api.eventbus.Event; import com.condation.cms.api.eventbus.EventBus; @@ -35,15 +34,12 @@ import com.condation.cms.api.eventbus.events.lifecycle.ServerReadyEvent; import com.condation.cms.api.eventbus.events.lifecycle.ServerShutdownInitiated; import com.condation.cms.core.eventbus.DefaultEventBus; -import com.condation.cms.server.VHost; import com.google.inject.Injector; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.jetty.http.HttpHeader; diff --git a/cms-server/src/main/java/com/condation/cms/server/VHost.java b/cms-server/src/main/java/com/condation/cms/server/VHost.java index e6606470b..5dbc1c356 100644 --- a/cms-server/src/main/java/com/condation/cms/server/VHost.java +++ b/cms-server/src/main/java/com/condation/cms/server/VHost.java @@ -72,7 +72,6 @@ import com.condation.cms.server.handler.module.JettyModuleHandler; import com.condation.cms.server.handler.module.JettyRouteHandler; import com.condation.cms.server.handler.module.JettyRoutesHandler; -import com.condation.cms.server.FileFolderPathResource; import com.condation.cms.server.filter.CreateRequestContextFilter; import com.condation.cms.server.filter.InitRequestContextFilter; import com.condation.cms.server.filter.RequestLoggingFilter; @@ -84,7 +83,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.List; -import java.util.concurrent.ScheduledExecutorService; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.eclipse.jetty.http.pathmap.PathSpec; diff --git a/cms-server/src/main/java/com/condation/cms/server/configs/ModulesModule.java b/cms-server/src/main/java/com/condation/cms/server/configs/ModulesModule.java index a75e0fcf0..b51c9320f 100644 --- a/cms-server/src/main/java/com/condation/cms/server/configs/ModulesModule.java +++ b/cms-server/src/main/java/com/condation/cms/server/configs/ModulesModule.java @@ -27,19 +27,20 @@ import com.condation.cms.api.SiteProperties; import com.condation.cms.api.configuration.Configuration; import com.condation.cms.api.eventbus.EventBus; -import com.condation.cms.api.extensions.HookSystemRegisterExtentionPoint; import com.condation.cms.api.extensions.MarkdownRendererProviderExtentionPoint; import com.condation.cms.api.extensions.TemplateEngineProviderExtentionPoint; import com.condation.cms.api.feature.features.ConfigurationFeature; import com.condation.cms.api.feature.features.CronJobSchedulerFeature; import com.condation.cms.api.feature.features.DBFeature; import com.condation.cms.api.feature.features.EventBusFeature; +import com.condation.cms.api.feature.features.MessagingFeature; import com.condation.cms.api.feature.features.ModuleManagerFeature; import com.condation.cms.api.feature.features.ServerPropertiesFeature; import com.condation.cms.api.feature.features.SitePropertiesFeature; import com.condation.cms.api.feature.features.ThemeFeature; import com.condation.cms.api.hooks.HookSystem; import com.condation.cms.api.markdown.MarkdownRenderer; +import com.condation.cms.api.messaging.Messaging; import com.condation.cms.api.module.CMSModuleContext; import com.condation.cms.api.module.CMSRequestContext; import com.condation.cms.api.request.ThreadLocalRequestContext; @@ -120,12 +121,13 @@ public ModuleRequestContextFactory requestContextFactory () { @Provides @Singleton public CMSModuleContext moduleContext(SiteProperties siteProperties, ServerProperties serverProperties, FileDB db, EventBus eventBus, Theme theme, - Configuration configuration, SiteCronJobScheduler cronJobScheduler) { + Configuration configuration, SiteCronJobScheduler cronJobScheduler, Messaging messaging) { final CMSModuleContext cmsModuleContext = new CMSModuleContext(); cmsModuleContext.add(SitePropertiesFeature.class, new SitePropertiesFeature(siteProperties)); cmsModuleContext.add(ServerPropertiesFeature.class, new ServerPropertiesFeature(serverProperties)); cmsModuleContext.add(DBFeature.class, new DBFeature(db)); cmsModuleContext.add(EventBusFeature.class, new EventBusFeature(eventBus)); + cmsModuleContext.add(MessagingFeature.class, new MessagingFeature(messaging)); cmsModuleContext.add(ThemeFeature.class, new ThemeFeature(theme)); cmsModuleContext.add(ConfigurationFeature.class, new ConfigurationFeature(configuration)); cmsModuleContext.add(CronJobSchedulerFeature.class, new CronJobSchedulerFeature(cronJobScheduler)); diff --git a/cms-server/src/main/java/com/condation/cms/server/configs/ServerGlobalModule.java b/cms-server/src/main/java/com/condation/cms/server/configs/ServerGlobalModule.java index 936073c3c..b6eb3fcc7 100644 --- a/cms-server/src/main/java/com/condation/cms/server/configs/ServerGlobalModule.java +++ b/cms-server/src/main/java/com/condation/cms/server/configs/ServerGlobalModule.java @@ -34,7 +34,6 @@ import org.graalvm.polyglot.Engine; import org.quartz.Scheduler; import org.quartz.SchedulerException; -import org.quartz.SchedulerFactory; import org.quartz.impl.DirectSchedulerFactory; import org.quartz.simpl.RAMJobStore; import org.quartz.simpl.SimpleThreadPool; diff --git a/cms-server/src/main/java/com/condation/cms/server/configs/SiteModule.java b/cms-server/src/main/java/com/condation/cms/server/configs/SiteModule.java index 984145846..5ec5ef3a2 100644 --- a/cms-server/src/main/java/com/condation/cms/server/configs/SiteModule.java +++ b/cms-server/src/main/java/com/condation/cms/server/configs/SiteModule.java @@ -39,6 +39,7 @@ import com.condation.cms.api.feature.features.ConfigurationFeature; import com.condation.cms.api.feature.features.DBFeature; import com.condation.cms.api.feature.features.EventBusFeature; +import com.condation.cms.api.feature.features.MessagingFeature; import com.condation.cms.api.feature.features.ServerPropertiesFeature; import com.condation.cms.api.feature.features.SitePropertiesFeature; import com.condation.cms.api.feature.features.ThemeFeature; @@ -46,6 +47,7 @@ import com.condation.cms.api.media.MediaService; import com.condation.cms.core.messages.DefaultMessageSource; import com.condation.cms.api.messages.MessageSource; +import com.condation.cms.api.messaging.Messaging; import com.condation.cms.api.scheduler.CronJobContext; import com.condation.cms.api.template.TemplateEngine; import com.condation.cms.api.theme.Theme; @@ -65,6 +67,8 @@ import com.condation.cms.media.SiteMediaManager; import com.condation.cms.request.RequestContextFactory; import com.condation.cms.content.template.functions.taxonomy.TaxonomyFunction; +import com.condation.cms.core.eventbus.MessagingEventBus; +import com.condation.cms.core.messaging.DefaultMessaging; import com.condation.cms.core.scheduler.SiteCronJobScheduler; import com.condation.cms.core.theme.DefaultTheme; import com.condation.modules.api.ModuleManager; @@ -93,13 +97,19 @@ public class SiteModule extends AbstractModule { @Override protected void configure() { bind(Configuration.class).toInstance(configuration); - bind(EventBus.class).to(DefaultEventBus.class).in(Singleton.class); + bind(Messaging.class).to(DefaultMessaging.class).in(Singleton.class); + bind(EventBus.class).to(MessagingEventBus.class).in(Singleton.class); bind(ContentParser.class).to(DefaultContentParser.class).in(Singleton.class); bind(TaxonomyFunction.class).in(Singleton.class); - bind(ContentNodeMapper.class).in(Singleton.class); bind(TaxonomyResolver.class).in(Singleton.class); } + @Provides + @Singleton + public ContentNodeMapper contentNodeMapper (DB db, ContentParser contentParser) { + return new ContentNodeMapper(db, contentParser); + } + @Provides @Singleton public ConfigurationManagement configurationManagement(DB db, Configuration configuration, SiteCronJobScheduler scheduler, EventBus eventBus) throws IOException { @@ -256,13 +266,14 @@ public ViewResolver viewResolver(ContentRenderer contentRenderer, @Provides @Singleton public CronJobContext cronJobContext(SiteProperties siteProperties, ServerProperties serverProperties, FileDB db, EventBus eventBus, Theme theme, - Configuration configuration) { + Configuration configuration, Messaging messaging) { final CronJobContext cronJobContext = new CronJobContext(); cronJobContext.add(SitePropertiesFeature.class, new SitePropertiesFeature(siteProperties)); cronJobContext.add(ServerPropertiesFeature.class, new ServerPropertiesFeature(serverProperties)); cronJobContext.add(DBFeature.class, new DBFeature(db)); cronJobContext.add(EventBusFeature.class, new EventBusFeature(eventBus)); cronJobContext.add(ThemeFeature.class, new ThemeFeature(theme)); + cronJobContext.add(MessagingFeature.class, new MessagingFeature(messaging)); cronJobContext.add(ConfigurationFeature.class, new ConfigurationFeature(configuration)); return cronJobContext; diff --git a/integration-tests/src/test/java/com/condation/cms/integration/tests/ConfigurationManagementReloadTest.java b/integration-tests/src/test/java/com/condation/cms/integration/tests/ConfigurationManagementReloadTest.java index ad31b266e..8cee073dc 100644 --- a/integration-tests/src/test/java/com/condation/cms/integration/tests/ConfigurationManagementReloadTest.java +++ b/integration-tests/src/test/java/com/condation/cms/integration/tests/ConfigurationManagementReloadTest.java @@ -141,13 +141,5 @@ public void publish(T event) { @Override public void register(Class eventClass, EventListener listener) { } - - @Override - public void unregister(Class eventClass, EventListener listener) { - } - - @Override - public void unregister(EventListener listener) { - } } } diff --git a/modules-framework/api/pom.xml b/modules-framework/api/pom.xml index 34da0cc36..5f82b2b71 100644 --- a/modules-framework/api/pom.xml +++ b/modules-framework/api/pom.xml @@ -14,10 +14,5 @@ com.google.code.gson gson - - com.google.auto.service - auto-service - true - \ No newline at end of file diff --git a/modules-framework/api/src/main/java/com/condation/modules/api/annotation/ExtensionAnnotationProcessor.java b/modules-framework/api/src/main/java/com/condation/modules/api/annotation/ExtensionAnnotationProcessor.java index 85d8dab23..3f0ae2a41 100644 --- a/modules-framework/api/src/main/java/com/condation/modules/api/annotation/ExtensionAnnotationProcessor.java +++ b/modules-framework/api/src/main/java/com/condation/modules/api/annotation/ExtensionAnnotationProcessor.java @@ -25,7 +25,6 @@ -import com.google.auto.service.AutoService; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; @@ -55,7 +54,6 @@ import javax.tools.StandardLocation; @SupportedAnnotationTypes("com.condation.modules.api.annotation.Extension") -@AutoService(Processor.class) public class ExtensionAnnotationProcessor extends AbstractProcessor implements Processor { @Override diff --git a/modules-framework/api/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/modules-framework/api/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 000000000..8be52f338 --- /dev/null +++ b/modules-framework/api/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +com.condation.modules.api.annotation.ExtensionAnnotationProcessor diff --git a/pom.xml b/pom.xml index f6881f488..5152ca620 100644 --- a/pom.xml +++ b/pom.xml @@ -283,11 +283,6 @@ semver4j 5.4.0 - - com.google.auto.service - auto-service - 1.1.1 - com.google.code.gson gson