refactored ModuleRegistry to singleton system

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-09-12 00:38:28 +02:00
parent e8e215f24c
commit bfe87f53a8
23 changed files with 140 additions and 163 deletions

View File

@@ -32,7 +32,6 @@ import java.util.function.BiFunction;
public class MessageSystem implements PostBox {
public static final System.Logger LOG = System.getLogger(MessageSystem.class.getSimpleName());
private final Timer timer = new Timer();
private final ModuleRegistry registry;
private record Receiver(User user, de.srsoftware.umbrella.core.model.Message message){}
@@ -72,7 +71,7 @@ public class MessageSystem implements PostBox {
private String debugAddress;
private final HashMap<Receiver,List<Exception>> exceptions = new HashMap<>();
public MessageSystem(ModuleRegistry moduleRegistry, Configuration config) throws UmbrellaException {
public MessageSystem(Configuration config) throws UmbrellaException {
var dbFile = config.get(CONFIG_DB).orElseThrow(() -> missingConfigException(CONFIG_DB));
db = new SqliteMessageDb(connect(dbFile));
debugAddress = config.get(DEBUG_ADDREESS).map(Object::toString).orElse(null);
@@ -81,7 +80,7 @@ public class MessageSystem implements PostBox {
user = config.get(CONFIG_SMTP_USER).map(Object::toString).orElseThrow(() -> new RuntimeException("umbrella.modules.message.smtp.user not configured!"));
pass = config.get(CONFIG_SMTP_PASS).map(Object::toString).orElseThrow(() -> new RuntimeException("umbrella.modules.message.smtp.pass not configured!"));
from = user;
registry = moduleRegistry.add(this);
ModuleRegistry.add(this);
new SubmissionTask(8).schedule();
new SubmissionTask(10).schedule();
new SubmissionTask(12).schedule();
@@ -117,7 +116,7 @@ public class MessageSystem implements PostBox {
var date = new Date();
for (var receiver : dueRecipients){
BiFunction<String,Map<String,String>,String> translateFunction = (text,fills) -> registry.translator().translate(receiver.language(),text,fills);
BiFunction<String,Map<String,String>,String> translateFunction = (text,fills) -> ModuleRegistry.translator().translate(receiver.language(),text,fills);
var combined = new CombinedMessage("Collected messages",translateFunction);
var envelopes = queue.stream().filter(env -> env.isFor(receiver)).toList();