From c8141c375532551fc2b9f5a6f84bd77472621582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Mon, 22 Jan 2024 18:50:23 +0100 Subject: [PATCH] refactoring of events and event building --- .../main/java/org/xbib/event/ClockEvent.java | 4 + .../src/main/java/org/xbib/event/Event.java | 38 +++++- .../java/org/xbib/event/FileFollowEvent.java | 4 + .../main/java/org/xbib/event/Listener.java | 7 ++ .../main/java/org/xbib/event/PathEvent.java | 4 + .../src/main/java/org/xbib/event/Payload.java | 15 +++ .../main/java/org/xbib/event/TimerEvent.java | 4 + .../java/org/xbib/event/clock/ClockEvent.java | 12 -- .../org/xbib/event/clock/ClockEventImpl.java | 23 ---- .../event/clock/ClockEventManagerService.java | 21 ++-- .../xbib/event/clock/ClockEventService.java | 16 ++- .../event/clock/SimpleClockEventConsumer.java | 4 +- .../org/xbib/event/common/ClockEventImpl.java | 10 ++ .../org/xbib/event/common/EventBuilder.java | 111 ++++++++++++++++++ .../java/org/xbib/event/common/EventImpl.java | 110 ++++++++++++++--- .../org/xbib/event/common/EventManager.java | 5 +- .../event/common/FileFollowEventImpl.java | 10 ++ .../xbib/event/common/GenericEventImpl.java | 29 +++++ .../org/xbib/event/common/PathEventImpl.java | 10 ++ .../org/xbib/event/common/TimerEventImpl.java | 10 ++ .../org/xbib/event/generic/GenericEvent.java | 6 - .../xbib/event/generic/GenericEventImpl.java | 31 ----- .../generic/GenericEventManagerService.java | 18 ++- .../java/org/xbib/event/generic/Listener.java | 7 -- .../org/xbib/event/path/FileFollowEvent.java | 16 --- .../xbib/event/path/FileFollowEventImpl.java | 35 ------ .../path/FileFollowEventManagerService.java | 9 +- .../event/path/FileFollowEventService.java | 18 +-- .../java/org/xbib/event/path/PathEvent.java | 26 ---- .../org/xbib/event/path/PathEventImpl.java | 66 ----------- .../event/path/PathEventManagerService.java | 30 ++--- .../org/xbib/event/path/PathEventService.java | 105 ++++------------- .../java/org/xbib/event/timer/TimerEvent.java | 12 -- .../org/xbib/event/timer/TimerEventImpl.java | 23 ---- .../event/timer/TimerEventManagerService.java | 16 +-- .../xbib/event/timer/TimerEventService.java | 51 ++++---- .../java/org/xbib/event/EventManagerTest.java | 79 ------------- .../event/clock/ClockEventManagerTest.java | 4 +- .../org/xbib/event/clock/TestClockEvent.java | 6 + .../event/clock/TestClockEventConsumer.java | 2 +- .../generic/GenericEventManagerTest.java | 99 ++++++++++++++++ .../path/FileFollowEventManagerTest.java | 4 +- .../xbib/event/path/TestFileFollowEvent.java | 6 + .../path/TestFileFollowEventConsumer.java | 2 +- .../org/xbib/event/timer/TestTimerEvent.java | 7 ++ .../event/timer/TestTimerEventConsumer.java | 3 +- .../event/timer/TimerEventManagerTest.java | 10 +- .../net/http/HttpEventReceiverService.java | 3 +- .../event/syslog/DefaultSyslogMessage.java | 20 ---- .../java/org/xbib/event/syslog/Message.java | 3 +- .../org/xbib/event/syslog/MessageEncoder.java | 4 +- 51 files changed, 589 insertions(+), 579 deletions(-) create mode 100644 event-api/src/main/java/org/xbib/event/ClockEvent.java create mode 100644 event-api/src/main/java/org/xbib/event/FileFollowEvent.java create mode 100644 event-api/src/main/java/org/xbib/event/Listener.java create mode 100644 event-api/src/main/java/org/xbib/event/PathEvent.java create mode 100644 event-api/src/main/java/org/xbib/event/Payload.java create mode 100644 event-api/src/main/java/org/xbib/event/TimerEvent.java delete mode 100644 event-common/src/main/java/org/xbib/event/clock/ClockEvent.java delete mode 100644 event-common/src/main/java/org/xbib/event/clock/ClockEventImpl.java create mode 100644 event-common/src/main/java/org/xbib/event/common/ClockEventImpl.java create mode 100644 event-common/src/main/java/org/xbib/event/common/EventBuilder.java create mode 100644 event-common/src/main/java/org/xbib/event/common/FileFollowEventImpl.java create mode 100644 event-common/src/main/java/org/xbib/event/common/GenericEventImpl.java create mode 100644 event-common/src/main/java/org/xbib/event/common/PathEventImpl.java create mode 100644 event-common/src/main/java/org/xbib/event/common/TimerEventImpl.java delete mode 100644 event-common/src/main/java/org/xbib/event/generic/GenericEvent.java delete mode 100644 event-common/src/main/java/org/xbib/event/generic/GenericEventImpl.java delete mode 100644 event-common/src/main/java/org/xbib/event/generic/Listener.java delete mode 100644 event-common/src/main/java/org/xbib/event/path/FileFollowEvent.java delete mode 100644 event-common/src/main/java/org/xbib/event/path/FileFollowEventImpl.java delete mode 100644 event-common/src/main/java/org/xbib/event/path/PathEvent.java delete mode 100644 event-common/src/main/java/org/xbib/event/path/PathEventImpl.java delete mode 100644 event-common/src/main/java/org/xbib/event/timer/TimerEvent.java delete mode 100644 event-common/src/main/java/org/xbib/event/timer/TimerEventImpl.java delete mode 100644 event-common/src/test/java/org/xbib/event/EventManagerTest.java create mode 100644 event-common/src/test/java/org/xbib/event/generic/GenericEventManagerTest.java diff --git a/event-api/src/main/java/org/xbib/event/ClockEvent.java b/event-api/src/main/java/org/xbib/event/ClockEvent.java new file mode 100644 index 0000000..94cefa5 --- /dev/null +++ b/event-api/src/main/java/org/xbib/event/ClockEvent.java @@ -0,0 +1,4 @@ +package org.xbib.event; + +public interface ClockEvent extends Event { +} diff --git a/event-api/src/main/java/org/xbib/event/Event.java b/event-api/src/main/java/org/xbib/event/Event.java index f6873e7..2f15388 100644 --- a/event-api/src/main/java/org/xbib/event/Event.java +++ b/event-api/src/main/java/org/xbib/event/Event.java @@ -1,14 +1,44 @@ package org.xbib.event; -import java.util.Map; +import java.io.IOException; +import java.nio.file.Path; +import java.time.Instant; public interface Event { - void setType(String type); + boolean isNullEvent(); + + Listener getListener(); String getType(); - void setMap(Map map); + String getCode(); - Map getMap(); + String getMessage(); + + Instant getCreated(); + + Instant getScheduledFor(); + + Payload getPayload(); + + Path getPath(); + + String getBase(); + + String getSuffix(); + + long getFileSize(); + + void success() throws IOException; + + void fail() throws IOException; + + String INCOMING = "incoming"; + + String SUCCESS = "success"; + + String FAIL = "fail"; + + String toJson() throws IOException; } diff --git a/event-api/src/main/java/org/xbib/event/FileFollowEvent.java b/event-api/src/main/java/org/xbib/event/FileFollowEvent.java new file mode 100644 index 0000000..3181a3a --- /dev/null +++ b/event-api/src/main/java/org/xbib/event/FileFollowEvent.java @@ -0,0 +1,4 @@ +package org.xbib.event; + +public interface FileFollowEvent extends Event { +} diff --git a/event-api/src/main/java/org/xbib/event/Listener.java b/event-api/src/main/java/org/xbib/event/Listener.java new file mode 100644 index 0000000..23d0974 --- /dev/null +++ b/event-api/src/main/java/org/xbib/event/Listener.java @@ -0,0 +1,7 @@ +package org.xbib.event; + +@FunctionalInterface +public interface Listener { + + void listen(Event event); +} diff --git a/event-api/src/main/java/org/xbib/event/PathEvent.java b/event-api/src/main/java/org/xbib/event/PathEvent.java new file mode 100644 index 0000000..4d394c3 --- /dev/null +++ b/event-api/src/main/java/org/xbib/event/PathEvent.java @@ -0,0 +1,4 @@ +package org.xbib.event; + +public interface PathEvent extends Event { +} diff --git a/event-api/src/main/java/org/xbib/event/Payload.java b/event-api/src/main/java/org/xbib/event/Payload.java new file mode 100644 index 0000000..85c135a --- /dev/null +++ b/event-api/src/main/java/org/xbib/event/Payload.java @@ -0,0 +1,15 @@ +package org.xbib.event; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class Payload extends LinkedHashMap { + + public Payload() { + super(); + } + + public Payload(Map map) { + super(map); + } +} diff --git a/event-api/src/main/java/org/xbib/event/TimerEvent.java b/event-api/src/main/java/org/xbib/event/TimerEvent.java new file mode 100644 index 0000000..2a7123a --- /dev/null +++ b/event-api/src/main/java/org/xbib/event/TimerEvent.java @@ -0,0 +1,4 @@ +package org.xbib.event; + +public interface TimerEvent extends Event { +} diff --git a/event-common/src/main/java/org/xbib/event/clock/ClockEvent.java b/event-common/src/main/java/org/xbib/event/clock/ClockEvent.java deleted file mode 100644 index 06e75f2..0000000 --- a/event-common/src/main/java/org/xbib/event/clock/ClockEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.xbib.event.clock; - -import org.xbib.event.Event; - -import java.time.Instant; - -public interface ClockEvent extends Event { - - void setInstant(Instant instant); - - Instant getInstant(); -} diff --git a/event-common/src/main/java/org/xbib/event/clock/ClockEventImpl.java b/event-common/src/main/java/org/xbib/event/clock/ClockEventImpl.java deleted file mode 100644 index 68ed2c6..0000000 --- a/event-common/src/main/java/org/xbib/event/clock/ClockEventImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.xbib.event.clock; - -import org.xbib.event.common.EventImpl; - -import java.time.Instant; - -public class ClockEventImpl extends EventImpl implements ClockEvent { - - private Instant instant; - - public ClockEventImpl() { - } - - @Override - public void setInstant(Instant instant) { - this.instant = instant; - } - - @Override - public Instant getInstant() { - return instant; - } -} diff --git a/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java b/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java index 2f721dc..631b2c4 100644 --- a/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/clock/ClockEventManagerService.java @@ -31,7 +31,6 @@ public class ClockEventManagerService implements EventManagerService { public ClockEventManagerService init(EventManager eventManager) { Settings settings = eventManager.getSettings(); EventBus eventBus = eventManager.getEventBus(); - ClassLoader classLoader = eventManager.getClassLoader(); this.suspended = new ArrayList<>(); ThreadFactory threadFactory = new ThreadFactory() { int n = 1; @@ -43,24 +42,18 @@ public class ClockEventManagerService implements EventManagerService { ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(settings.getAsInt("pool.size", 2), threadFactory); this.cronSchedule = new CronSchedule<>(scheduledExecutorService); - for (Map.Entry clockEventService : settings.getGroups("event.clock").entrySet()) { - String name = clockEventService.getKey(); - Settings entrySettings = clockEventService.getValue(); + for (Map.Entry mapEntry : settings.getGroups("event.clock").entrySet()) { + String name = mapEntry.getKey(); + Settings entrySettings = mapEntry.getValue(); if (entrySettings.getAsBoolean("enabled", true)) { String entry = entrySettings.get("entry"); if (entry != null) { try { - String className = entrySettings.get("class"); - if (className != null) { - @SuppressWarnings("unchecked") - Class eventClass = (Class) classLoader.loadClass(className); - cronSchedule.add(className, CronExpression.parse(entry), new ClockEventService(this, eventBus, name, eventClass)); - logger.log(Level.INFO, "cron job " + clockEventService.getKey() + " scheduled on " + entry + ", event class " + className); - } else { - logger.log(Level.WARNING, "no class specified"); - } + ClockEventService clockEventService = new ClockEventService(this, eventBus, name); + cronSchedule.add(name, CronExpression.parse(entry), clockEventService); + logger.log(Level.INFO, "cron job " + name + " scheduled on " + entry); } catch (Exception e) { - logger.log(Level.WARNING, "unable to schedule cron job " + clockEventService.getKey() + ", reason " + e.getMessage()); + logger.log(Level.WARNING, "unable to schedule cron job " + mapEntry.getKey() + ", reason " + e.getMessage()); } } } else { diff --git a/event-common/src/main/java/org/xbib/event/clock/ClockEventService.java b/event-common/src/main/java/org/xbib/event/clock/ClockEventService.java index 04b54f4..d845fbf 100644 --- a/event-common/src/main/java/org/xbib/event/clock/ClockEventService.java +++ b/event-common/src/main/java/org/xbib/event/clock/ClockEventService.java @@ -1,10 +1,12 @@ package org.xbib.event.clock; -import java.time.Instant; import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.logging.Logger; + +import org.xbib.event.Event; import org.xbib.event.bus.EventBus; +import org.xbib.event.common.EventImpl; public class ClockEventService implements Callable { @@ -16,16 +18,12 @@ public class ClockEventService implements Callable { private final String name; - private final Class eventClass; - public ClockEventService(ClockEventManagerService manager, EventBus eventBus, - String name, - Class eventClass) { + String name) { this.manager = manager; this.eventBus = eventBus; this.name = name; - this.eventClass = eventClass; } @Override @@ -35,9 +33,9 @@ public class ClockEventService implements Callable { logger.log(Level.FINE, "clock event " + name + " suspended"); return 1; } else { - logger.log(Level.FINE, "posting clock event " + eventClass.getName()); - ClockEvent clockEvent = eventClass.getDeclaredConstructor().newInstance(); - clockEvent.setInstant(Instant.now()); + Event clockEvent = EventImpl.builder() + .setType("clock") + .build(); eventBus.post(clockEvent); return 0; } diff --git a/event-common/src/main/java/org/xbib/event/clock/SimpleClockEventConsumer.java b/event-common/src/main/java/org/xbib/event/clock/SimpleClockEventConsumer.java index 9c9fbc2..3eabd12 100644 --- a/event-common/src/main/java/org/xbib/event/clock/SimpleClockEventConsumer.java +++ b/event-common/src/main/java/org/xbib/event/clock/SimpleClockEventConsumer.java @@ -1,8 +1,8 @@ package org.xbib.event.clock; +import org.xbib.event.ClockEvent; import org.xbib.event.EventConsumer; -import java.io.IOException; import java.util.logging.Logger; import org.xbib.event.bus.AllowConcurrentEvents; import org.xbib.event.bus.Subscribe; @@ -17,7 +17,7 @@ public class SimpleClockEventConsumer implements EventConsumer { @Subscribe @AllowConcurrentEvents void onEvent(ClockEvent event) { - logger.info("received demo clock event, instant = " + event.getInstant()); + logger.info("received demo clock event, created = " + event.getCreated()); } } diff --git a/event-common/src/main/java/org/xbib/event/common/ClockEventImpl.java b/event-common/src/main/java/org/xbib/event/common/ClockEventImpl.java new file mode 100644 index 0000000..18bf24f --- /dev/null +++ b/event-common/src/main/java/org/xbib/event/common/ClockEventImpl.java @@ -0,0 +1,10 @@ +package org.xbib.event.common; + +import org.xbib.event.ClockEvent; + +public class ClockEventImpl extends EventImpl implements ClockEvent { + + public ClockEventImpl(EventBuilder builder) { + super(builder); + } +} diff --git a/event-common/src/main/java/org/xbib/event/common/EventBuilder.java b/event-common/src/main/java/org/xbib/event/common/EventBuilder.java new file mode 100644 index 0000000..0727459 --- /dev/null +++ b/event-common/src/main/java/org/xbib/event/common/EventBuilder.java @@ -0,0 +1,111 @@ +package org.xbib.event.common; + +import org.xbib.event.Event; +import org.xbib.event.Listener; +import org.xbib.event.Payload; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Instant; + +public class EventBuilder { + + Listener listener; + + String type; + + String code; + + String message; + + Instant scheduled; + + Instant created; + + Payload payload; + + Path path; + + String base; + + String suffix; + + long fileSize; + + long maxFileSize; + + EventBuilder() { + this.maxFileSize = -1L; + } + + public EventBuilder setListener(Listener listener) { + this.listener = listener; + return this; + } + + public EventBuilder setType(String type) { + this.type = type; + return this; + } + + public EventBuilder setCode(String code) { + this.code = code; + return this; + } + + public EventBuilder setMessage(String message) { + this.message = message; + return this; + } + + public EventBuilder setScheduledFor(Instant scheduled) { + this.scheduled = scheduled; + return this; + } + + public EventBuilder setPayload(Payload payload) { + this.payload = payload; + return this; + } + + public EventBuilder setMaxFileSize(long maxFileSize) { + this.maxFileSize = maxFileSize; + return this; + } + + public EventBuilder setPath(Path path) throws IOException { + this.path = path; + base = getBase(path); + suffix = getSuffix(path); + fileSize = Files.size(path); + if (maxFileSize != -1L && fileSize > maxFileSize) { + throw new IOException("file size too large"); + } + return this; + } + + public Event build() { + this.created = Instant.now(); + return switch (type) { + case "clock" -> new ClockEventImpl(this); + case "timer" -> new TimerEventImpl(this); + case "path" -> new PathEventImpl(this); + case "filefollow" -> new FileFollowEventImpl(this); + case "generic" -> new GenericEventImpl(this, listener); + default -> new EventImpl(this); + }; + } + + private static String getBase(Path path) { + String name = path.getFileName().toString(); + int pos = name.lastIndexOf('.'); + return pos >= 0 ? name.substring(0, pos) : name; + } + + private static String getSuffix(Path path) { + String name = path.getFileName().toString(); + int pos = name.lastIndexOf('.'); + return pos >= 0 ? name.substring(pos + 1) : null; + } +} diff --git a/event-common/src/main/java/org/xbib/event/common/EventImpl.java b/event-common/src/main/java/org/xbib/event/common/EventImpl.java index 01e904a..96895ea 100644 --- a/event-common/src/main/java/org/xbib/event/common/EventImpl.java +++ b/event-common/src/main/java/org/xbib/event/common/EventImpl.java @@ -2,52 +2,124 @@ package org.xbib.event.common; import org.xbib.datastructures.json.tiny.Json; import org.xbib.event.Event; +import org.xbib.event.Listener; +import org.xbib.event.Payload; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.FileTime; +import java.time.Instant; import java.util.Map; public class EventImpl implements Event { - private String type; + private final EventBuilder builder; - private Map map; - - public EventImpl() { + EventImpl(EventBuilder builder) { + this.builder = builder; } - @Override - public void setType(String type) { - this.type = type; + public static EventBuilder builder() { + return new EventBuilder(); + } + + public Listener getListener() { + return builder.listener; } @Override public String getType() { - return type; + return builder.type; } @Override - public void setMap(Map map) { - this.map = map; + public String getCode() { + return builder.code; } @Override - public Map getMap() { - return map; + public String getMessage() { + return builder.message; } - public static EventImpl fromJson(String json) { + @Override + public Payload getPayload() { + return builder.payload; + } + + @Override + public Instant getCreated() { + return builder.created; + } + + @Override + public Instant getScheduledFor() { + return builder.scheduled; + } + + @Override + public Path getPath() { + return builder.path; + } + + @Override + public String getBase() { + return builder.base; + } + + @Override + public String getSuffix() { + return builder.suffix; + } + + @Override + public long getFileSize() { + return builder.fileSize; + } + + + public static Event fromFile(Path file) throws IOException { + return fromJson(Files.readString(file)); + } + + public static Event fromJson(String json) { Map map = Json.toMap(json); - EventImpl event = new EventImpl(); - event.setType((String) map.get("type")); - event.setMap(map); - return event; + return builder() + .setType(map.getOrDefault("type", "generic").toString()) + .setPayload(new Payload(map)) + .build(); } public String toJson() throws IOException { - return Json.toString(map); + return Json.toString(builder.payload); } + @Override public boolean isNullEvent() { - return type == null; + return builder.type == null; + } + + @Override + public String toString() { + return "Event[path = " + builder.path + ", base = " + builder.base + ", suffix = " + builder.suffix + " payload = " + builder.payload +"]"; + } + + public void success() throws IOException { + if (builder.path != null) { + Files.setLastModifiedTime(builder.path, FileTime.from(Instant.now())); + Files.move(builder.path, builder.path.getParent().resolve(Event.SUCCESS) + .resolve(builder.path.getFileName()).toAbsolutePath(), + StandardCopyOption.REPLACE_EXISTING); + + } + } + + public void fail() throws IOException { + Files.setLastModifiedTime(builder.path, FileTime.from(Instant.now())); + Files.move(builder.path, builder.path.getParent().resolve(Event.FAIL) + .resolve(builder.path.getFileName()).toAbsolutePath(), + StandardCopyOption.REPLACE_EXISTING); } } diff --git a/event-common/src/main/java/org/xbib/event/common/EventManager.java b/event-common/src/main/java/org/xbib/event/common/EventManager.java index 6d4e18e..3c88271 100644 --- a/event-common/src/main/java/org/xbib/event/common/EventManager.java +++ b/event-common/src/main/java/org/xbib/event/common/EventManager.java @@ -73,8 +73,9 @@ public final class EventManager { getGenericEventManagerService().post(event); } - public EventManagerService getEventManagerService(Class cl) { - return eventManagerServices.get(cl); + @SuppressWarnings("unchecked") + public T getEventManagerService(Class cl) { + return (T) eventManagerServices.get(cl); } public GenericEventManagerService getGenericEventManagerService() { diff --git a/event-common/src/main/java/org/xbib/event/common/FileFollowEventImpl.java b/event-common/src/main/java/org/xbib/event/common/FileFollowEventImpl.java new file mode 100644 index 0000000..6708681 --- /dev/null +++ b/event-common/src/main/java/org/xbib/event/common/FileFollowEventImpl.java @@ -0,0 +1,10 @@ +package org.xbib.event.common; + +import org.xbib.event.FileFollowEvent; + +public class FileFollowEventImpl extends EventImpl implements FileFollowEvent { + + public FileFollowEventImpl(EventBuilder builder) { + super(builder); + } +} diff --git a/event-common/src/main/java/org/xbib/event/common/GenericEventImpl.java b/event-common/src/main/java/org/xbib/event/common/GenericEventImpl.java new file mode 100644 index 0000000..0b36727 --- /dev/null +++ b/event-common/src/main/java/org/xbib/event/common/GenericEventImpl.java @@ -0,0 +1,29 @@ +package org.xbib.event.common; + +import org.xbib.event.Listener; + +import java.util.Objects; + +public class GenericEventImpl extends EventImpl { + + private final EventBuilder builder; + + public GenericEventImpl(EventBuilder builder) { + this(builder, null); + } + + public GenericEventImpl(EventBuilder builder, Listener listener) { + super(builder); + this.builder = builder; + this.builder.listener = Objects.requireNonNull(listener); + } + + public GenericEventImpl setListener(Listener listener) { + this.builder.listener = Objects.requireNonNull(listener); + return this; + } + + public void received() { + builder.listener.listen(this); + } +} diff --git a/event-common/src/main/java/org/xbib/event/common/PathEventImpl.java b/event-common/src/main/java/org/xbib/event/common/PathEventImpl.java new file mode 100644 index 0000000..88c5c4b --- /dev/null +++ b/event-common/src/main/java/org/xbib/event/common/PathEventImpl.java @@ -0,0 +1,10 @@ +package org.xbib.event.common; + +import org.xbib.event.PathEvent; + +public class PathEventImpl extends EventImpl implements PathEvent { + + public PathEventImpl(EventBuilder builder) { + super(builder); + } +} diff --git a/event-common/src/main/java/org/xbib/event/common/TimerEventImpl.java b/event-common/src/main/java/org/xbib/event/common/TimerEventImpl.java new file mode 100644 index 0000000..30954da --- /dev/null +++ b/event-common/src/main/java/org/xbib/event/common/TimerEventImpl.java @@ -0,0 +1,10 @@ +package org.xbib.event.common; + +import org.xbib.event.TimerEvent; + +public class TimerEventImpl extends EventImpl implements TimerEvent { + + public TimerEventImpl(EventBuilder builder) { + super(builder); + } +} diff --git a/event-common/src/main/java/org/xbib/event/generic/GenericEvent.java b/event-common/src/main/java/org/xbib/event/generic/GenericEvent.java deleted file mode 100644 index 033ccca..0000000 --- a/event-common/src/main/java/org/xbib/event/generic/GenericEvent.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.xbib.event.generic; - -import org.xbib.event.Event; - -public interface GenericEvent extends Event { -} diff --git a/event-common/src/main/java/org/xbib/event/generic/GenericEventImpl.java b/event-common/src/main/java/org/xbib/event/generic/GenericEventImpl.java deleted file mode 100644 index c3b4c22..0000000 --- a/event-common/src/main/java/org/xbib/event/generic/GenericEventImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.xbib.event.generic; - -import org.xbib.event.common.EventImpl; - -public class GenericEventImpl extends EventImpl implements GenericEvent { - - private Listener listener; - - public GenericEventImpl() { - this(null); - } - - public GenericEventImpl(Listener listener) { - this.listener = listener; - } - - public GenericEventImpl setListener(Listener listener) { - this.listener = listener; - return this; - } - - public Listener getListener() { - return listener; - } - - public void received() { - if (listener != null) { - listener.listen(this); - } - } -} diff --git a/event-common/src/main/java/org/xbib/event/generic/GenericEventManagerService.java b/event-common/src/main/java/org/xbib/event/generic/GenericEventManagerService.java index e98fa9d..62ea75c 100644 --- a/event-common/src/main/java/org/xbib/event/generic/GenericEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/generic/GenericEventManagerService.java @@ -3,15 +3,22 @@ package org.xbib.event.generic; import java.io.IOException; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.xbib.event.Event; +import org.xbib.event.Listener; import org.xbib.event.bus.EventBus; import org.xbib.event.bus.Subscriber; import org.xbib.event.bus.SubscriberRegistry; import org.xbib.event.common.EventManager; import org.xbib.event.common.EventManagerService; +import org.xbib.event.common.GenericEventImpl; public class GenericEventManagerService implements EventManagerService { + private static final Logger logger = Logger.getLogger(GenericEventManagerService.class.getName()); + private EventBus eventBus; public GenericEventManagerService() { @@ -33,9 +40,10 @@ public class GenericEventManagerService implements EventManagerService { } public void post(GenericEventImpl event, - CompletableFuture future) { + CompletableFuture future) { SubscriberRegistry subscriberRegistry = eventBus.getSubscribers(); Set set = subscriberRegistry.getSubscribersForTesting(event.getClass()); + logger.log(Level.INFO, "set = " + set); event.setListener(new WrappedListener(event.getListener(), set.size(), future)); post(event); } @@ -46,18 +54,20 @@ public class GenericEventManagerService implements EventManagerService { private int size; - private final CompletableFuture future; + private final CompletableFuture future; - public WrappedListener(Listener listener, int size, CompletableFuture future) { + public WrappedListener(Listener listener, int size, CompletableFuture future) { this.listener = listener; this.size = size; this.future = future; } @Override - public void listen(GenericEvent event) { + public void listen(Event event) { if (listener != null) { listener.listen(event); + } else { + logger.log(Level.WARNING, "listener not set"); } if (--size == 0) { future.complete(event); diff --git a/event-common/src/main/java/org/xbib/event/generic/Listener.java b/event-common/src/main/java/org/xbib/event/generic/Listener.java deleted file mode 100644 index 20a70aa..0000000 --- a/event-common/src/main/java/org/xbib/event/generic/Listener.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.xbib.event.generic; - -@FunctionalInterface -public interface Listener { - - void listen(GenericEvent event); -} diff --git a/event-common/src/main/java/org/xbib/event/path/FileFollowEvent.java b/event-common/src/main/java/org/xbib/event/path/FileFollowEvent.java deleted file mode 100644 index 4bc25e2..0000000 --- a/event-common/src/main/java/org/xbib/event/path/FileFollowEvent.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.xbib.event.path; - -import org.xbib.event.Event; - -import java.nio.file.Path; - -public interface FileFollowEvent extends Event { - - void setPath(Path path); - - Path getPath(); - - void setContent(String content); - - String getContent(); -} diff --git a/event-common/src/main/java/org/xbib/event/path/FileFollowEventImpl.java b/event-common/src/main/java/org/xbib/event/path/FileFollowEventImpl.java deleted file mode 100644 index 7f94125..0000000 --- a/event-common/src/main/java/org/xbib/event/path/FileFollowEventImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.xbib.event.path; - -import org.xbib.event.common.EventImpl; - -import java.nio.file.Path; - -public class FileFollowEventImpl extends EventImpl implements FileFollowEvent { - - private Path path; - - private String content; - - public FileFollowEventImpl() { - } - - @Override - public void setPath(Path path) { - this.path = path; - } - - @Override - public Path getPath() { - return path; - } - - @Override - public void setContent(String content) { - this.content = content; - } - - @Override - public String getContent() { - return content; - } -} diff --git a/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java b/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java index 1500e4f..6a3a057 100644 --- a/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/path/FileFollowEventManagerService.java @@ -5,7 +5,6 @@ import org.xbib.event.common.EventManager; import org.xbib.event.common.EventManagerService; import org.xbib.settings.Settings; -import java.io.Closeable; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -27,12 +26,10 @@ public class FileFollowEventManagerService implements EventManagerService { public FileFollowEventManagerService() { } - @SuppressWarnings("unchecked") @Override public FileFollowEventManagerService init(EventManager eventManager) { Settings settings = eventManager.getSettings(); EventBus eventBus = eventManager.getEventBus(); - ClassLoader classLoader = eventManager.getClassLoader(); ExecutorService executorService = eventManager.getExecutorService(); this.eventServiceMap = new LinkedHashMap<>(); for (Map.Entry entry : settings.getGroups("event.filefollow").entrySet()) { @@ -45,12 +42,10 @@ public class FileFollowEventManagerService implements EventManagerService { try { Path base = Paths.get(baseStr); Pattern pattern = Pattern.compile(patternStr); - String className = definition.get("class", FileFollowEventImpl.class.getName()); - Class eventClass = (Class) classLoader.loadClass(className); - FileFollowEventService fileFollowEventService = new FileFollowEventService(definition, eventBus, base, pattern, eventClass); + FileFollowEventService fileFollowEventService = new FileFollowEventService(definition, eventBus, base, pattern); Future future = executorService.submit(fileFollowEventService); eventServiceMap.put(future, fileFollowEventService); - logger.log(Level.INFO, "file follow service " + entry.getKey() + " with base " + base + " and pattern " + pattern + " added, event class " + className); + logger.log(Level.INFO, "file follow service " + entry.getKey() + " with base " + base + " and pattern " + pattern + " added"); } catch (Exception e) { logger.log(Level.SEVERE, "unable to create file follow service " + entry.getKey() + ", reason " + e.getMessage(), e); } diff --git a/event-common/src/main/java/org/xbib/event/path/FileFollowEventService.java b/event-common/src/main/java/org/xbib/event/path/FileFollowEventService.java index 4943e45..e28f541 100644 --- a/event-common/src/main/java/org/xbib/event/path/FileFollowEventService.java +++ b/event-common/src/main/java/org/xbib/event/path/FileFollowEventService.java @@ -1,6 +1,8 @@ package org.xbib.event.path; +import org.xbib.event.Event; import org.xbib.event.bus.EventBus; +import org.xbib.event.common.EventImpl; import org.xbib.settings.Settings; import java.io.Closeable; @@ -37,8 +39,6 @@ public class FileFollowEventService implements Callable, Closeable { private final Pattern pattern; - private final Class eventClass; - private final WatchService watchService; private final Map fileSizes; @@ -48,12 +48,10 @@ public class FileFollowEventService implements Callable, Closeable { public FileFollowEventService(Settings settings, EventBus eventBus, Path base, - Pattern pattern, - Class eventClass) throws IOException { + Pattern pattern) throws IOException { this.eventBus = eventBus; this.base = base; this.pattern = pattern; - this.eventClass = eventClass; FileSystem fileSystem = base.getFileSystem(); this.watchService = fileSystem.newWatchService(); WatchEvent.Kind[] kinds = new WatchEvent.Kind[1]; @@ -91,10 +89,12 @@ public class FileFollowEventService implements Callable, Closeable { String content = readRange(channel, lastSize, currentSize); // split content by line, this allows pattern matching without preprocessing in worker for (String line : content.split("\n")) { - FileFollowEvent event = eventClass.getDeclaredConstructor().newInstance(); - event.setType(base.toString()); - event.setPath(path); - event.setContent(line); + Event event = EventImpl.builder() + .setType("filefollow") + .setCode(base.toString()) + .setPath(path) + .setMessage(line) + .build(); eventBus.post(event); } } diff --git a/event-common/src/main/java/org/xbib/event/path/PathEvent.java b/event-common/src/main/java/org/xbib/event/path/PathEvent.java deleted file mode 100644 index dca3e83..0000000 --- a/event-common/src/main/java/org/xbib/event/path/PathEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.xbib.event.path; - -import org.xbib.event.Event; - -import java.io.IOException; -import java.nio.file.Path; - -public interface PathEvent extends Event { - - void setPath(Path path); - - Path getPath(); - - void setFile(Path file); - - Path getFile(); - - void setSuffix(String suffix); - - String getSuffix(); - - void success() throws IOException; - - void fail() throws IOException; - -} diff --git a/event-common/src/main/java/org/xbib/event/path/PathEventImpl.java b/event-common/src/main/java/org/xbib/event/path/PathEventImpl.java deleted file mode 100644 index 9dbd6b3..0000000 --- a/event-common/src/main/java/org/xbib/event/path/PathEventImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.xbib.event.path; - -import org.xbib.event.common.EventImpl; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.FileTime; -import java.time.Instant; - -public class PathEventImpl extends EventImpl implements PathEvent { - - private Path path; - - private Path file; - - private String suffix; - - @Override - public void setPath(Path path) { - this.path = path; - } - - @Override - public Path getPath() { - return path; - } - - @Override - public void setFile(Path file) { - this.file = file; - } - - @Override - public Path getFile() { - return file; - } - - @Override - public void setSuffix(String suffix) { - this.suffix = suffix; - } - - @Override - public String getSuffix() { - return suffix; - } - - public void success() throws IOException { - Files.setLastModifiedTime(file, FileTime.from(Instant.now())); - Files.move(file, path.resolve(PathEventService.SUCCESS).resolve(file.getFileName()).toAbsolutePath(), - StandardCopyOption.REPLACE_EXISTING); - } - - public void fail() throws IOException { - Files.setLastModifiedTime(file, FileTime.from(Instant.now())); - Files.move(file, path.resolve(PathEventService.FAIL).resolve(file.getFileName()).toAbsolutePath(), - StandardCopyOption.REPLACE_EXISTING); - } - - @Override - public String toString() { - return "path=" + path + " file=" + file + " suffix=" + suffix + " map=" + getMap(); - } -} diff --git a/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java b/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java index 6596bad..ca11d58 100644 --- a/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/path/PathEventManagerService.java @@ -2,6 +2,7 @@ package org.xbib.event.path; import org.xbib.datastructures.api.TimeValue; import org.xbib.datastructures.json.tiny.Json; +import org.xbib.event.Event; import org.xbib.event.bus.EventBus; import org.xbib.event.common.EventManager; import org.xbib.event.common.EventManagerService; @@ -55,12 +56,9 @@ public class PathEventManagerService implements EventManagerService { String name = entry.getKey(); Settings definition = entry.getValue(); if (definition.getAsBoolean("enabled", true)) { - int maxBytes = definition.getAsInt("maxfilesize", 10 * 1024 * 1024); // 10 MB TimeValue lifetime = definition.getAsTime("lifetime", TimeValue.timeValueHours(72)); - String className = definition.get("class", PathEventImpl.class.getName()); - Class eventClass = (Class) classLoader.loadClass(className); Path p = path.resolve(name); - createPathEventService(name, p, maxBytes, lifetime, eventClass); + createPathEventService(name, p, lifetime); } else { logger.log(Level.WARNING, "path servive definition not enabled in configuration"); } @@ -73,12 +71,10 @@ public class PathEventManagerService implements EventManagerService { public void createPathEventService(String name, Path path, - int maxBytes, - TimeValue lifetime, - Class eventClass) + TimeValue lifetime) throws IOException { createQueue(name, path); - PathEventService pathEventService = new PathEventService(this, eventBus, name, path, maxBytes, lifetime, eventClass); + PathEventService pathEventService = new PathEventService(this, eventBus, name, path, lifetime); add(pathEventService); } @@ -128,12 +124,12 @@ public class PathEventManagerService implements EventManagerService { public boolean put(String queue, String key, String suffix, String string) throws IOException { String keyFileName = key + suffix; Path queuePath = path.resolve(queue); - if (Files.exists(queuePath.resolve(PathEventService.INCOMING).resolve(keyFileName)) || - Files.exists(queuePath.resolve(PathEventService.SUCCESS).resolve(keyFileName))) { + if (Files.exists(queuePath.resolve(Event.INCOMING).resolve(keyFileName)) || + Files.exists(queuePath.resolve(Event.SUCCESS).resolve(keyFileName))) { logger.log(Level.WARNING, "key " + key + " already exists"); return false; } - Path p = queuePath.resolve(PathEventService.INCOMING).resolve(keyFileName); + Path p = queuePath.resolve(Event.INCOMING).resolve(keyFileName); try (Writer writer = Files.newBufferedWriter(p)) { writer.write(string); } @@ -153,20 +149,20 @@ public class PathEventManagerService implements EventManagerService { public boolean exists(String queue, String key, String suffix) { String keyFileName = key + suffix; Path queuePath = path.resolve(queue); - return Files.exists(queuePath.resolve(PathEventService.INCOMING).resolve(keyFileName)) || - Files.exists(queuePath.resolve(PathEventService.SUCCESS).resolve(keyFileName)); + return Files.exists(queuePath.resolve(Event.INCOMING).resolve(keyFileName)) || + Files.exists(queuePath.resolve(Event.SUCCESS).resolve(keyFileName)); } public long sizeOfIncoming(String queue) throws IOException { - return sizeOf(path.resolve(queue).resolve(PathEventService.INCOMING)); + return sizeOf(path.resolve(queue).resolve(Event.INCOMING)); } public long sizeOfSuccess(String queue) throws IOException { - return sizeOf(path.resolve(queue).resolve(PathEventService.SUCCESS)); + return sizeOf(path.resolve(queue).resolve(Event.SUCCESS)); } public long sizeOfFail(String queue) throws IOException { - return sizeOf(path.resolve(queue).resolve(PathEventService.FAIL)); + return sizeOf(path.resolve(queue).resolve(Event.FAIL)); } public static long sizeOf(Path path) throws IOException { @@ -179,7 +175,7 @@ public class PathEventManagerService implements EventManagerService { if (!Files.exists(p)) { logger.log(Level.FINE, "creating queue " + name + " at " + p); Files.createDirectories(p); - for (String s: List.of(PathEventService.INCOMING, PathEventService.SUCCESS, PathEventService.FAIL)) { + for (String s: List.of(Event.INCOMING, Event.SUCCESS, Event.FAIL)) { Path dir = p.resolve(s); if (!Files.exists(dir)) { logger.log(Level.FINE, "creating queue " + name + " dir " + dir); diff --git a/event-common/src/main/java/org/xbib/event/path/PathEventService.java b/event-common/src/main/java/org/xbib/event/path/PathEventService.java index f22cb85..e612383 100644 --- a/event-common/src/main/java/org/xbib/event/path/PathEventService.java +++ b/event-common/src/main/java/org/xbib/event/path/PathEventService.java @@ -1,8 +1,9 @@ package org.xbib.event.path; import org.xbib.datastructures.api.TimeValue; -import org.xbib.datastructures.json.tiny.Json; +import org.xbib.event.Event; import org.xbib.event.bus.EventBus; +import org.xbib.event.common.EventImpl; import java.io.Closeable; import java.io.IOException; @@ -26,11 +27,6 @@ public class PathEventService implements Callable, Closeable { private static final Logger logger = Logger.getLogger(PathEventService.class.getName()); - public static final String INCOMING = "incoming"; - - public static final String SUCCESS = "success"; - - public static final String FAIL = "fail"; private final PathEventManagerService pathEventManager; @@ -40,11 +36,7 @@ public class PathEventService implements Callable, Closeable { private final String name; - private final int maxFileSize; - private final TimeValue lifetime; -; - private final Class pathEventClass; private final WatchService watchService; @@ -56,22 +48,18 @@ public class PathEventService implements Callable, Closeable { EventBus eventBus, String name, Path path, - int maxFileSize, - TimeValue lifetime, - Class pathEventClass) throws IOException { + TimeValue lifetime) throws IOException { this.pathEventManager = pathEventManager; this.eventBus = eventBus; this.name = name; this.path = path; - this.maxFileSize = maxFileSize; this.lifetime = lifetime; - this.pathEventClass = pathEventClass; drainIncoming(); this.watchService = path.getFileSystem().newWatchService(); WatchEvent.Kind[] kinds = new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_CREATE }; - WatchKey watchKey = path.resolve(INCOMING).register(watchService, kinds); + WatchKey watchKey = path.resolve(Event.INCOMING).register(watchService, kinds); keepWatching = true; - logger.log(Level.INFO, "path event service created for incoming files at " + path + " max file size = " + maxFileSize); + logger.log(Level.INFO, "path event service created for incoming files at " + path); } public String getName() { @@ -83,7 +71,7 @@ public class PathEventService implements Callable, Closeable { @Override public Integer call() { try { - logger.log(Level.INFO, "watch service running on " + path.resolve(INCOMING)); + logger.log(Level.INFO, "watch service running on " + path.resolve(Event.INCOMING)); while (keepWatching && watchService != null) { WatchKey watchKey = watchService.take(); logger.log(Level.FINE, "received a watch key " + watchKey); @@ -96,12 +84,12 @@ public class PathEventService implements Callable, Closeable { Thread.sleep(1000L); WatchEvent pathWatchEvent = (WatchEvent) watchEvent; String watchEventContext = pathWatchEvent.context().toString(); - Path p = path.resolve(INCOMING).resolve(watchEventContext); + Path p = path.resolve(Event.INCOMING).resolve(watchEventContext); logger.log(Level.FINE, "watch event " + pathWatchEvent + " context = " + watchEventContext + " path = " + p); if (pathEventManager.getSuspendedQueues().contains(name)) { - failEvent(watchEventContext, p); + failEvent(p); } else { - postEvent(watchEventContext, p); + postEvent(p); } } watchKey.reset(); @@ -127,14 +115,8 @@ public class PathEventService implements Callable, Closeable { } public void drainIncoming() throws IOException { - try (DirectoryStream stream = Files.newDirectoryStream(path.resolve(INCOMING))) { - stream.forEach(path -> { - if (Files.isRegularFile(path)) { - String key = path.getFileName().toString(); - logger.log(Level.INFO, "while draining found key = " + key + " path = " + path); - postEvent(key, path); - } - }); + try (DirectoryStream stream = Files.newDirectoryStream(path.resolve(Event.INCOMING))) { + stream.forEach(this::postEvent); } } @@ -163,67 +145,22 @@ public class PathEventService implements Callable, Closeable { } } - private void postEvent(String key, Path file) { - PathEvent event = toEvent(key, file); - if (event != null) { - logger.log(Level.FINE, "posting new event = " + event.getClass()); + private void postEvent(Path file) { + try { + Event event = EventImpl.fromFile(file); eventBus.post(event); eventCount++; + } catch (IOException e) { + logger.log(Level.SEVERE, "ignoring event post because of " + e.getMessage()); } } - private void failEvent(String key, Path file) throws IOException { - PathEvent event = toEvent(key, file); - if (event != null) { - logger.log(Level.WARNING, "queue " + name + " suspended, event short-circuited to fail"); + private void failEvent(Path file) { + try { + Event event = EventImpl.fromFile(file); event.fail(); - } - } - - private static String getBase(String name) { - int pos = name.lastIndexOf('.'); - return pos >= 0 ? name.substring(0, pos) : name; - } - - private static String getSuffix(String name) { - int pos = name.lastIndexOf('.'); - return pos >= 0 ? name.substring(pos + 1) : null; - } - - private PathEvent toEvent(String key, Path file) { - try { - String base = getBase(key); - String suffix = getSuffix(key); - long fileSize = Files.size(file); - if (fileSize > maxFileSize) { - logger.log(Level.SEVERE, "event object ignored, too large"); - return null; - } - if ("!json".equals(suffix)) { - logger.log(Level.SEVERE, "event object ignored, no json suffix"); - return null; - } - String json = Files.readString(file); - return toEvent(base, file, suffix, json); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - logger.log(Level.SEVERE, "event object could not be created"); - return null; - } - - private PathEvent toEvent(String base, Path file, String suffix, String json) { - try { - PathEvent event = pathEventClass.getConstructor().newInstance(); - event.setType(base); - event.setFile(file); - event.setSuffix(suffix); - event.setPath(path); // remember directory for fail() and success() - event.setMap(Json.toMap(json)); - return event; - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - return null; + } catch (IOException e) { + logger.log(Level.SEVERE, "unable to fail event because of " + e.getMessage()); } } } diff --git a/event-common/src/main/java/org/xbib/event/timer/TimerEvent.java b/event-common/src/main/java/org/xbib/event/timer/TimerEvent.java deleted file mode 100644 index 000ee85..0000000 --- a/event-common/src/main/java/org/xbib/event/timer/TimerEvent.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.xbib.event.timer; - -import org.xbib.event.Event; - -import java.time.Instant; - -public interface TimerEvent extends Event { - - void setInstant(Instant instant); - - Instant getInstant(); -} diff --git a/event-common/src/main/java/org/xbib/event/timer/TimerEventImpl.java b/event-common/src/main/java/org/xbib/event/timer/TimerEventImpl.java deleted file mode 100644 index 2e61297..0000000 --- a/event-common/src/main/java/org/xbib/event/timer/TimerEventImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.xbib.event.timer; - -import org.xbib.event.common.EventImpl; - -import java.time.Instant; - -public class TimerEventImpl extends EventImpl implements TimerEvent { - - private Instant instant; - - public TimerEventImpl() { - } - - @Override - public void setInstant(Instant instant) { - this.instant = instant; - } - - @Override - public Instant getInstant() { - return instant; - } -} diff --git a/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java b/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java index b46bc8d..b5dd10f 100644 --- a/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java +++ b/event-common/src/main/java/org/xbib/event/timer/TimerEventManagerService.java @@ -1,5 +1,6 @@ package org.xbib.event.timer; +import org.xbib.event.Payload; import org.xbib.event.bus.EventBus; import org.xbib.event.common.EventManager; import org.xbib.event.common.EventManagerService; @@ -38,12 +39,11 @@ public class TimerEventManagerService implements EventManagerService { for (Map.Entry entry : settings.getGroups("event.timer").entrySet()) { String name = entry.getKey(); Settings timerSettings = entry.getValue(); - String className = timerSettings.get("class", TimerEvent.class.getName()); try { - Class eventClass = (Class) classLoader.loadClass(className); PersistenceStore persistenceStore = new FilePersistenceStore(timerSettings, name); - services.put(name, new TimerEventService(eventBus, name, eventClass, ZoneId.systemDefault(), persistenceStore)); - logger.log(Level.INFO, "timer " + name + " active for timer event class " + className); + TimerEventService timerEventService = new TimerEventService(eventBus, name, ZoneId.systemDefault(), persistenceStore); + services.put(name, timerEventService); + logger.log(Level.INFO, "timer " + name + " active: " + timerEventService); } catch (Exception e) { logger.log(Level.WARNING, "unable to activate timer " + name + ", reason: " + e.getMessage(), e); } @@ -53,12 +53,12 @@ public class TimerEventManagerService implements EventManagerService { public boolean put(String service, String timeSpec, - Map map) throws ParseException, IOException { + Payload payload) throws ParseException, IOException { if (services.containsKey(service)) { Span span = Chronic.parse(timeSpec); if (span != null) { ZonedDateTime zonedDateTime = span.getBeginCalendar(); - services.get(service).schedule(zonedDateTime.toInstant(), map); + services.get(service).schedule(zonedDateTime.toInstant(), payload); logger.log(Level.INFO, "scheduled to " + zonedDateTime); } else { logger.log(Level.INFO, "timer event key " + service + ": can not understand time spec " + timeSpec); @@ -73,9 +73,9 @@ public class TimerEventManagerService implements EventManagerService { public boolean put(String service, Instant instant, - Map map) throws IOException { + Payload payload) throws IOException { if (services.containsKey(service)) { - services.get(service).schedule(instant, map); + services.get(service).schedule(instant, payload); return true; } else { logger.log(Level.SEVERE, "unknown timer event key: " + service); diff --git a/event-common/src/main/java/org/xbib/event/timer/TimerEventService.java b/event-common/src/main/java/org/xbib/event/timer/TimerEventService.java index e745442..9be77a3 100644 --- a/event-common/src/main/java/org/xbib/event/timer/TimerEventService.java +++ b/event-common/src/main/java/org/xbib/event/timer/TimerEventService.java @@ -1,18 +1,19 @@ package org.xbib.event.timer; +import org.xbib.event.Event; +import org.xbib.event.Payload; import org.xbib.event.bus.EventBus; +import org.xbib.event.common.EventImpl; import org.xbib.event.persistence.PersistenceStore; import java.io.Closeable; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -27,8 +28,6 @@ class TimerEventService implements Closeable { private final EventBus eventBus; - private final Class eventClass; - private final ZoneId zoneId; private final PersistenceStore persistenceStore; @@ -37,11 +36,9 @@ class TimerEventService implements Closeable { public TimerEventService(EventBus eventBus, String name, - Class eventClass, ZoneId zoneId, PersistenceStore persistenceStore) throws IOException { this.eventBus = eventBus; - this.eventClass = eventClass; this.zoneId = zoneId; this.persistenceStore = persistenceStore; this.timer = new Timer(); @@ -49,13 +46,12 @@ class TimerEventService implements Closeable { logger.log(Level.INFO, "timer event service " + name + " loaded and rescheduled, " + tasknum + " timer tasks"); } - void schedule(Instant instant, Map map) throws IOException { - ZonedDateTime zonedDateTime = instant.atZone(zoneId); - Map task = new LinkedHashMap<>(map); - task.put("scheduled", zonedDateTime.format(DateTimeFormatter.ISO_DATE_TIME)); - TimerEventTask timerEventTask = new TimerEventTask(task); + void schedule(Instant instant, Payload payload) throws IOException { + String scheduled = instant.atZone(zoneId).format(DateTimeFormatter.ISO_DATE_TIME); + payload.put("scheduled", scheduled); + TimerEventTask timerEventTask = new TimerEventTask(payload); timer.schedule(timerEventTask, Date.from(instant)); - logger.log(Level.INFO, "new task " + map + " added, scheduled at " + instant); + logger.log(Level.INFO, "new task " + payload + " added, scheduled at " + scheduled); } @SuppressWarnings("unchecked") @@ -66,11 +62,12 @@ class TimerEventService implements Closeable { persistenceStore.clear(); persistenceStore.commit(); for (Map task : tasks) { + Payload payload = new Payload(task); ZonedDateTime scheduledDate = ZonedDateTime.parse((String) task.get("scheduled"), DateTimeFormatter.ISO_DATE_TIME); if (scheduledDate.isBefore(ZonedDateTime.now())) { logger.log(Level.WARNING, "scheduled timer task " + task + " date already passed"); } else { - schedule(scheduledDate.toInstant(), task); + schedule(scheduledDate.toInstant(), payload); } } tasks = (List>) persistenceStore.getOrDefault("tasks", new ArrayList<>()); @@ -90,45 +87,45 @@ class TimerEventService implements Closeable { public class TimerEventTask extends TimerTask { - private final Map map; + private final Payload payload; - public TimerEventTask(Map map) throws IOException { - this.map = map; - persistenceStore.insert("tasks", this.map); + public TimerEventTask(Payload payload) throws IOException { + this.payload = payload; + persistenceStore.insert("tasks", this.payload); } @Override public void run() { - TimerEvent timerEvent; try { - timerEvent = eventClass.getDeclaredConstructor().newInstance(); - timerEvent.setInstant(Instant.now()); - timerEvent.setMap(map); - logger.log(Level.FINE, "posting timer event " + timerEvent.getClass().getName() + " map = " + map); + Event timerEvent = EventImpl.builder() + .setType("timer") + .setPayload(payload) + .build(); + logger.log(Level.FINE, "posting timer event " + timerEvent.getClass().getName() + " with payload = " + payload); eventBus.post(timerEvent); logger.log(Level.FINE, "persistence before remove: " + persistenceStore.get("tasks")); - if (persistenceStore.remove("tasks", this.map)) { + if (persistenceStore.remove("tasks", this.payload)) { logger.log(Level.FINE, "removal done"); } logger.log(Level.FINE, "persistence after remove: " + persistenceStore.get("tasks")); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | IOException e) { + } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage(), e); } } @Override public String toString() { - return map.toString(); + return payload.toString(); } @Override public int hashCode() { - return map.hashCode(); + return payload.hashCode(); } @Override public boolean equals(Object object) { - return object instanceof TimerEventTask && Objects.equals(map, ((TimerEventTask) object).map); + return object instanceof TimerEventTask && Objects.equals(payload, ((TimerEventTask) object).payload); } } } diff --git a/event-common/src/test/java/org/xbib/event/EventManagerTest.java b/event-common/src/test/java/org/xbib/event/EventManagerTest.java deleted file mode 100644 index f7d5177..0000000 --- a/event-common/src/test/java/org/xbib/event/EventManagerTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.xbib.event; - -import org.junit.jupiter.api.Test; -import org.xbib.event.bus.Subscribe; -import org.xbib.event.common.EventManager; -import org.xbib.event.generic.GenericEventImpl; -import org.xbib.event.generic.GenericEvent; -import org.xbib.settings.Settings; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class EventManagerTest { - - private static final Logger logger = Logger.getLogger(EventManagerTest.class.getName()); - - @Test - void testGenericEvents() { - Settings settings = Settings.settingsBuilder() - .build(); - TestEventConsumer consumer = new TestEventConsumer(); - EventManager eventManager = EventManager.builder(settings) - .register(consumer) - .build(); - eventManager.getGenericEventManagerService().post(new GenericEventImpl(e -> { - logger.log(Level.INFO, "received event " + e); - })); - } - - - @Test - void testGenericEventWithWaitForSubscriber() throws InterruptedException, ExecutionException { - Settings settings = Settings.settingsBuilder() - .build(); - TestEventConsumer consumer = new TestEventConsumer(); - EventManager eventManager = EventManager.builder(settings) - .register(consumer) - .build(); - CompletableFuture future = new CompletableFuture<>(); - eventManager.getGenericEventManagerService().post(new GenericEventImpl(e -> { - logger.log(Level.INFO, "received event " + e); - future.complete(e); - })); - GenericEvent e = future.get(); - logger.log(Level.INFO, "the event was received with result " + e + ", continuing"); - } - - @Test - void testGenericEventWithWaitForAllConsumers() throws ExecutionException, InterruptedException { - Settings settings = Settings.settingsBuilder() - .build(); - TestEventConsumer consumer1 = new TestEventConsumer(); - TestEventConsumer consumer2 = new TestEventConsumer(); - EventManager eventManager = EventManager.builder(settings) - .register(consumer1) - .register(consumer2) - .loadEventConsumers() - .build(); - CompletableFuture future = new CompletableFuture<>(); - eventManager.getGenericEventManagerService().post(new GenericEventImpl(e -> { - logger.log(Level.INFO, "received event " + e); - }), future); - GenericEvent e = future.get(); - logger.log(Level.INFO, "the event " + e + " was received by all consumers, continuing"); - } - - private static class TestEventConsumer implements EventConsumer { - - TestEventConsumer() { - } - - @Subscribe - public void onEvent(GenericEventImpl event) { - event.received(); - } - } -} diff --git a/event-common/src/test/java/org/xbib/event/clock/ClockEventManagerTest.java b/event-common/src/test/java/org/xbib/event/clock/ClockEventManagerTest.java index b2dfa3c..5b03cf1 100644 --- a/event-common/src/test/java/org/xbib/event/clock/ClockEventManagerTest.java +++ b/event-common/src/test/java/org/xbib/event/clock/ClockEventManagerTest.java @@ -13,10 +13,10 @@ public class ClockEventManagerTest { TestClockEventConsumer clockEventConsumer = new TestClockEventConsumer(); Settings settings = Settings.settingsBuilder() .put("event.clock.testclockevent.enabled", "true") - .put("event.clock.testclockevent.class", "org.xbib.event.clock.TestClockEvent") .put("event.clock.testclockevent.entry", "*/1 6-21 * * *") .build(); - EventManager eventManager = EventManager.builder(settings) + EventManager eventManager = EventManager.builder() + .setSettings(settings) .register(clockEventConsumer) .build(); Thread.sleep(90000L); diff --git a/event-common/src/test/java/org/xbib/event/clock/TestClockEvent.java b/event-common/src/test/java/org/xbib/event/clock/TestClockEvent.java index 53ccb89..fe5e7fc 100644 --- a/event-common/src/test/java/org/xbib/event/clock/TestClockEvent.java +++ b/event-common/src/test/java/org/xbib/event/clock/TestClockEvent.java @@ -1,4 +1,10 @@ package org.xbib.event.clock; +import org.xbib.event.common.ClockEventImpl; +import org.xbib.event.common.EventBuilder; + public class TestClockEvent extends ClockEventImpl { + public TestClockEvent(EventBuilder builder) { + super(builder); + } } diff --git a/event-common/src/test/java/org/xbib/event/clock/TestClockEventConsumer.java b/event-common/src/test/java/org/xbib/event/clock/TestClockEventConsumer.java index afacd21..76fd882 100644 --- a/event-common/src/test/java/org/xbib/event/clock/TestClockEventConsumer.java +++ b/event-common/src/test/java/org/xbib/event/clock/TestClockEventConsumer.java @@ -16,6 +16,6 @@ public class TestClockEventConsumer implements EventConsumer { @Subscribe @AllowConcurrentEvents void onEvent(TestClockEvent event) { - logger.log(Level.INFO, "received test clock event on " + Instant.now() + " event instant = " + event.getInstant()); + logger.log(Level.INFO, "received test clock event on " + Instant.now() + " event instant = " + event.getCreated()); } } diff --git a/event-common/src/test/java/org/xbib/event/generic/GenericEventManagerTest.java b/event-common/src/test/java/org/xbib/event/generic/GenericEventManagerTest.java new file mode 100644 index 0000000..15e9820 --- /dev/null +++ b/event-common/src/test/java/org/xbib/event/generic/GenericEventManagerTest.java @@ -0,0 +1,99 @@ +package org.xbib.event.generic; + +import org.junit.jupiter.api.Test; +import org.xbib.event.Event; +import org.xbib.event.EventConsumer; +import org.xbib.event.bus.Subscribe; +import org.xbib.event.common.EventImpl; +import org.xbib.event.common.EventManager; +import org.xbib.event.common.GenericEventImpl; +import org.xbib.settings.Settings; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class GenericEventManagerTest { + + private static final Logger logger = Logger.getLogger(GenericEventManagerTest.class.getName()); + + @Test + void testGenericEvents() { + Settings settings = Settings.settingsBuilder() + .build(); + TestEventConsumer consumer = new TestEventConsumer(); + EventManager eventManager = EventManager.builder() + .setSettings(settings) + .register(consumer) + .build(); + Event event = EventImpl.builder() + .setType("generic") + .setListener(e -> logger.log(Level.INFO, "received event " + e)) + .build(); + eventManager.getGenericEventManagerService().post(event); + } + + + @Test + void testGenericEventWithWaitForSubscriber() throws InterruptedException, ExecutionException { + Settings settings = Settings.settingsBuilder() + .build(); + TestEventConsumer consumer = new TestEventConsumer(); + EventManager eventManager = EventManager.builder() + .setSettings(settings) + .register(consumer) + .build(); + CompletableFuture future = new CompletableFuture<>(); + Event event = EventImpl.builder() + .setType("generic") + .setListener(e -> { + logger.log(Level.INFO, "received event " + e); + future.complete(e); + }) + .build(); + eventManager.getGenericEventManagerService().post(event); + Event e = future.get(); + logger.log(Level.INFO, "the event was received with result " + e + ", continuing"); + } + + @Test + void testGenericEventWithWaitForAllConsumers() throws ExecutionException, InterruptedException, TimeoutException { + Settings settings = Settings.settingsBuilder() + .build(); + TestEventConsumer consumer1 = new TestEventConsumer(); + TestEventConsumer consumer2 = new TestEventConsumer(); + EventManager eventManager = EventManager.builder() + .setSettings(settings) + .register(consumer1) + .register(consumer2) + .loadEventConsumers() + .build(); + CompletableFuture future = new CompletableFuture<>(); + Event event = GenericEventImpl.builder() + .setType("generic") + .setListener(e -> { + logger.log(Level.INFO, "received event " + e); + future.complete(e); + }) + .build(); + eventManager.getGenericEventManagerService().post((GenericEventImpl) event, future); + Event e = future.get(5L, TimeUnit.SECONDS); + if (e != null) { + logger.log(Level.INFO, "the event " + e + " was received by all consumers, continuing"); + } + } + + private static class TestEventConsumer implements EventConsumer { + + TestEventConsumer() { + } + + @Subscribe + public void onEvent(GenericEventImpl event) { + event.received(); + } + } +} diff --git a/event-common/src/test/java/org/xbib/event/path/FileFollowEventManagerTest.java b/event-common/src/test/java/org/xbib/event/path/FileFollowEventManagerTest.java index 30dd561..6cc51e1 100644 --- a/event-common/src/test/java/org/xbib/event/path/FileFollowEventManagerTest.java +++ b/event-common/src/test/java/org/xbib/event/path/FileFollowEventManagerTest.java @@ -21,11 +21,11 @@ public class FileFollowEventManagerTest { TestFileFollowEventConsumer consumer = new TestFileFollowEventConsumer(); Settings settings = Settings.settingsBuilder() .put("event.filefollow.testfilefollowevent.enabled", "true") - .put("event.filefollow.testfilefollowevent.class", "org.xbib.event.io.file.TestFileFollowEvent") .put("event.filefollow.testfilefollowevent.base", path.toString()) .put("event.filefollow.testfilefollowevent.pattern", ".*") .build(); - EventManager eventManager = EventManager.builder(settings) + EventManager eventManager = EventManager.builder() + .setSettings(settings) .register(consumer) .build(); Thread.sleep(5000L); diff --git a/event-common/src/test/java/org/xbib/event/path/TestFileFollowEvent.java b/event-common/src/test/java/org/xbib/event/path/TestFileFollowEvent.java index 59ce40f..71e5e1c 100644 --- a/event-common/src/test/java/org/xbib/event/path/TestFileFollowEvent.java +++ b/event-common/src/test/java/org/xbib/event/path/TestFileFollowEvent.java @@ -1,4 +1,10 @@ package org.xbib.event.path; +import org.xbib.event.common.EventBuilder; +import org.xbib.event.common.FileFollowEventImpl; + public class TestFileFollowEvent extends FileFollowEventImpl { + public TestFileFollowEvent(EventBuilder builder) { + super(builder); + } } diff --git a/event-common/src/test/java/org/xbib/event/path/TestFileFollowEventConsumer.java b/event-common/src/test/java/org/xbib/event/path/TestFileFollowEventConsumer.java index 9437d92..d84300d 100644 --- a/event-common/src/test/java/org/xbib/event/path/TestFileFollowEventConsumer.java +++ b/event-common/src/test/java/org/xbib/event/path/TestFileFollowEventConsumer.java @@ -14,6 +14,6 @@ public class TestFileFollowEventConsumer implements EventConsumer { @Subscribe @AllowConcurrentEvents void onEvent(TestFileFollowEvent event) { - logger.log(Level.INFO, "received filefollow event path = " + event.getPath() + " content = " + event.getContent()); + logger.log(Level.INFO, "received filefollow event path = " + event.getPath() + " content = " + event.getMessage()); } } diff --git a/event-common/src/test/java/org/xbib/event/timer/TestTimerEvent.java b/event-common/src/test/java/org/xbib/event/timer/TestTimerEvent.java index 93cbc86..8b894ca 100644 --- a/event-common/src/test/java/org/xbib/event/timer/TestTimerEvent.java +++ b/event-common/src/test/java/org/xbib/event/timer/TestTimerEvent.java @@ -1,4 +1,11 @@ package org.xbib.event.timer; +import org.xbib.event.common.EventBuilder; +import org.xbib.event.common.TimerEventImpl; + public class TestTimerEvent extends TimerEventImpl { + + public TestTimerEvent(EventBuilder builder) { + super(builder); + } } diff --git a/event-common/src/test/java/org/xbib/event/timer/TestTimerEventConsumer.java b/event-common/src/test/java/org/xbib/event/timer/TestTimerEventConsumer.java index 7164633..afaee4d 100644 --- a/event-common/src/test/java/org/xbib/event/timer/TestTimerEventConsumer.java +++ b/event-common/src/test/java/org/xbib/event/timer/TestTimerEventConsumer.java @@ -4,7 +4,6 @@ import org.xbib.event.EventConsumer; import org.xbib.event.bus.AllowConcurrentEvents; import org.xbib.event.bus.Subscribe; -import java.io.IOException; import java.time.Instant; import java.util.logging.Level; import java.util.logging.Logger; @@ -16,7 +15,7 @@ public class TestTimerEventConsumer implements EventConsumer { @Subscribe @AllowConcurrentEvents void onEvent(TestTimerEvent event) { - logger.log(Level.INFO, "received test timer event on " + Instant.now() + " event instant = " + event.getInstant()); + logger.log(Level.INFO, "received test timer event on " + Instant.now() + " event instant = " + event.getCreated()); } } diff --git a/event-common/src/test/java/org/xbib/event/timer/TimerEventManagerTest.java b/event-common/src/test/java/org/xbib/event/timer/TimerEventManagerTest.java index 7e21925..2304543 100644 --- a/event-common/src/test/java/org/xbib/event/timer/TimerEventManagerTest.java +++ b/event-common/src/test/java/org/xbib/event/timer/TimerEventManagerTest.java @@ -1,6 +1,7 @@ package org.xbib.event.timer; import org.junit.jupiter.api.Test; +import org.xbib.event.Payload; import org.xbib.event.common.EventManager; import org.xbib.settings.Settings; @@ -15,14 +16,15 @@ public class TimerEventManagerTest { TestTimerEventConsumer consumer = new TestTimerEventConsumer(); Settings settings = Settings.settingsBuilder() .put("event.timer.testtimerevent.enabled", "true") - .put("event.timer.testtimerevent.class", "org.xbib.event.timer.TestTimerEvent") .build(); - EventManager eventManager = EventManager.builder(settings) + EventManager eventManager = EventManager.builder() + .setSettings(settings) .register(consumer) .build(); TimerEventManagerService timerEventManager = eventManager.getTimerEventManagerService(); - timerEventManager.put("testtimerevent", Instant.now().plusSeconds(5L), Map.of("a", "b")); + Payload payload = new Payload(Map.of("a", "b")); + timerEventManager.put("testtimerevent", Instant.now().plusSeconds(5L), payload); Thread.sleep(10000L); - timerEventManager.close(); + timerEventManager.shutdown(); } } diff --git a/event-net-http/src/main/java/org/xbib/event/net/http/HttpEventReceiverService.java b/event-net-http/src/main/java/org/xbib/event/net/http/HttpEventReceiverService.java index dc00889..f3ecf0c 100644 --- a/event-net-http/src/main/java/org/xbib/event/net/http/HttpEventReceiverService.java +++ b/event-net-http/src/main/java/org/xbib/event/net/http/HttpEventReceiverService.java @@ -1,5 +1,6 @@ package org.xbib.event.net.http; +import org.xbib.event.Event; import org.xbib.event.common.EventManager; import org.xbib.event.common.EventImpl; import org.xbib.net.http.HttpHeaderNames; @@ -27,7 +28,7 @@ public class HttpEventReceiverService { .setPath("/event/{type}") .setMethod(HttpMethod.POST) .setHandler(ctx -> { - EventImpl event = EventImpl.fromJson(ctx.getRequest().asJson()); + Event event = EventImpl.fromJson(ctx.getRequest().asJson()); if (event.isNullEvent()) { ctx.status(NOT_FOUND).done(); } else { diff --git a/event-syslog/src/main/java/org/xbib/event/syslog/DefaultSyslogMessage.java b/event-syslog/src/main/java/org/xbib/event/syslog/DefaultSyslogMessage.java index 597ea3d..4012d5b 100644 --- a/event-syslog/src/main/java/org/xbib/event/syslog/DefaultSyslogMessage.java +++ b/event-syslog/src/main/java/org/xbib/event/syslog/DefaultSyslogMessage.java @@ -137,26 +137,6 @@ public class DefaultSyslogMessage implements SyslogMessage { return sb.toString(); } - @Override - public void setType(String key) { - // ignore - } - - @Override - public String getType() { - return builder.messageId; - } - - @Override - public void setMap(Map map) { - // ignore - } - - @Override - public Map getMap() { - return builder.map; - } - public static class Builder implements SyslogMessage.Builder { LocalDateTime date; diff --git a/event-syslog/src/main/java/org/xbib/event/syslog/Message.java b/event-syslog/src/main/java/org/xbib/event/syslog/Message.java index 3d2f9bb..3d7001d 100644 --- a/event-syslog/src/main/java/org/xbib/event/syslog/Message.java +++ b/event-syslog/src/main/java/org/xbib/event/syslog/Message.java @@ -1,7 +1,6 @@ package org.xbib.event.syslog; import org.xbib.datastructures.api.Builder; -import org.xbib.event.Event; import java.net.InetAddress; import java.time.LocalDateTime; @@ -10,7 +9,7 @@ import java.util.List; /** * Represents a standard syslog message. */ -public interface Message extends Event { +public interface Message { /** * Date of the message. This is the parsed date from the client. * diff --git a/event-syslog/src/main/java/org/xbib/event/syslog/MessageEncoder.java b/event-syslog/src/main/java/org/xbib/event/syslog/MessageEncoder.java index 0c7d8a9..0c2a8e4 100644 --- a/event-syslog/src/main/java/org/xbib/event/syslog/MessageEncoder.java +++ b/event-syslog/src/main/java/org/xbib/event/syslog/MessageEncoder.java @@ -63,7 +63,7 @@ public class MessageEncoder extends MessageToMessageEncoder { buffer.writeCharSequence(message.severity(), charset); buffer.writeBytes(pipe); int index = 0; - for (Map.Entry kvp : message.getMap().entrySet()) { + /*for (Map.Entry kvp : message.getMap().entrySet()) { if (index > 0) { buffer.writeBytes(EncoderHelper.SPACE); } @@ -71,7 +71,7 @@ public class MessageEncoder extends MessageToMessageEncoder { buffer.writeBytes(EncoderHelper.EQUALS); buffer.writeCharSequence(kvp.getValue().toString(), charset); index++; - } + }*/ output.add(buffer); }