From 104dde25688bf3ed8be37d78d80a1180eec9bc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Mon, 11 Dec 2023 12:06:16 +0100 Subject: [PATCH] use generic event future --- .../java/org/xbib/event/generic/GenericEventManager.java | 8 ++++---- src/test/java/org/xbib/event/EventManagerTest.java | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/xbib/event/generic/GenericEventManager.java b/src/main/java/org/xbib/event/generic/GenericEventManager.java index b899dd5..7abad9d 100644 --- a/src/main/java/org/xbib/event/generic/GenericEventManager.java +++ b/src/main/java/org/xbib/event/generic/GenericEventManager.java @@ -20,7 +20,7 @@ public class GenericEventManager { } public void post(DefaultGenericEvent event, - CompletableFuture future) { + CompletableFuture future) { SubscriberRegistry subscriberRegistry = eventBus.getSubscribers(); Set set = subscriberRegistry.getSubscribersForTesting(event.getClass()); event.setListener(new WrappedListener(event.getListener(), set.size(), future)); @@ -33,9 +33,9 @@ public class GenericEventManager { 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; @@ -47,7 +47,7 @@ public class GenericEventManager { listener.listen(event); } if (--size == 0) { - future.complete(true); + future.complete(event); } } } diff --git a/src/test/java/org/xbib/event/EventManagerTest.java b/src/test/java/org/xbib/event/EventManagerTest.java index 3744d35..cd99a8f 100644 --- a/src/test/java/org/xbib/event/EventManagerTest.java +++ b/src/test/java/org/xbib/event/EventManagerTest.java @@ -57,14 +57,12 @@ public class EventManagerTest { .register(consumer2) .loadEventConsumers() .build(); - CompletableFuture future = new CompletableFuture<>(); + CompletableFuture future = new CompletableFuture<>(); eventManager.getGenericEventManager().post(new DefaultGenericEvent(e -> { logger.log(Level.INFO, "received event " + e); }), future); - Boolean b = future.get(); - if (b != null && b) { - logger.log(Level.INFO, "the event was received by all consumers, continuing"); - } + GenericEvent e = future.get(); + logger.log(Level.INFO, "the event " + e + " was received by all consumers, continuing"); } private static class TestEventConsumer implements EventConsumer {