use generic event future
This commit is contained in:
parent
ef0a26bbd1
commit
104dde2568
2 changed files with 7 additions and 9 deletions
|
@ -20,7 +20,7 @@ public class GenericEventManager {
|
|||
}
|
||||
|
||||
public void post(DefaultGenericEvent event,
|
||||
CompletableFuture<Boolean> future) {
|
||||
CompletableFuture<GenericEvent> future) {
|
||||
SubscriberRegistry subscriberRegistry = eventBus.getSubscribers();
|
||||
Set<Subscriber> 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<Boolean> future;
|
||||
private final CompletableFuture<GenericEvent> future;
|
||||
|
||||
public WrappedListener(Listener listener, int size, CompletableFuture<Boolean> future) {
|
||||
public WrappedListener(Listener listener, int size, CompletableFuture<GenericEvent> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,14 +57,12 @@ public class EventManagerTest {
|
|||
.register(consumer2)
|
||||
.loadEventConsumers()
|
||||
.build();
|
||||
CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
CompletableFuture<GenericEvent> 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 {
|
||||
|
|
Loading…
Reference in a new issue