Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/


import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -32,6 +33,7 @@
*
* @author t.marx
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE })
public @interface FeatureScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,8 +47,7 @@
* @author t.marx
*/
@Slf4j
@RequiredArgsConstructor(onConstructor = @__({
@Inject}))
@RequiredArgsConstructor
public class ConfigurationManagement {

final DB db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@ public interface EventBus {
<T extends Event> void publish(final T event);

<T extends Event> void register(Class<T> eventClass, EventListener<T> listener);

public <T extends Event> void unregister(Class<T> eventClass, EventListener<T> listener);

public void unregister(EventListener listener);
}
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
*
* @author t.marx
*/
@RequiredArgsConstructor(onConstructor = @__({
@Inject}))
@RequiredArgsConstructor()
@Slf4j
public class ContentNodeMapper {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

/**
*
* @author t.marx
*/
public interface Listener<T> {
void receive (T data);
}
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #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);
}
60 changes: 60 additions & 0 deletions cms-api/src/main/java/com/condation/cms/api/messaging/Topic.java
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

/**
*
* @author t.marx
*/
public interface Topic {

public static enum Mode {
ASYNC, SYNC;
}

/**
* Subscribe to a topic.
*
* @param <RT>
* @param listener
* @param dataType
*/
<RT> void subscribe(Listener<RT> listener, Class<RT> 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);
}
}
4 changes: 4 additions & 0 deletions cms-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<groupId>com.condation.cms</groupId>
<artifactId>cms-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ private Multimap<Class<? extends Event>, EventListener> listeners () {
public <T extends Event> void register(Class<T> eventClass, EventListener<T> listener) {
listeners.put(eventClass, listener);
}

@Override
public <T extends Event> void unregister(Class<T> eventClass, EventListener<T> 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 <T extends Event> void publish(final T event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #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 <T extends Event> void register(Class<T> eventClass, EventListener<T> listener) {
messaging.topic(eventClass.getName()).subscribe((data) -> {
listener.consum(data);
}, eventClass);
}

@Override
public <T extends Event> void publish(final T event) {
messaging.topic(event.getClass().getName()).publish(event);
}

@Override
public <T extends Event> void syncPublish(T event) {
publish(event);
}
}
Original file line number Diff line number Diff line change
@@ -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
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #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<Class<? extends Event>, EventListener> listeners;

Map<String, DefaultTopic> topics;

@Inject
public DefaultMessaging () {
listeners = ArrayListMultimap.create();
topics = new HashMap<>();
}

@Override
public Topic topic(String name) {
return topics.computeIfAbsent(name, (topic) -> new DefaultTopic(topic));
}
}
Loading