From e5f585c413d76ebe45b385f5a3efe469e9460e85 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 18 Feb 2022 11:18:46 +0000 Subject: [PATCH] vetoable events --- core/src/main/groovy/com/muwire/core/Event.groovy | 1 + core/src/main/groovy/com/muwire/core/EventBus.groovy | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/Event.groovy b/core/src/main/groovy/com/muwire/core/Event.groovy index a956e3a4..c2aa7eaf 100644 --- a/core/src/main/groovy/com/muwire/core/Event.groovy +++ b/core/src/main/groovy/com/muwire/core/Event.groovy @@ -7,6 +7,7 @@ class Event { private static final AtomicLong SEQ_NO = new AtomicLong(); final long seqNo final long timestamp + boolean vetoed Event() { seqNo = SEQ_NO.getAndIncrement() diff --git a/core/src/main/groovy/com/muwire/core/EventBus.groovy b/core/src/main/groovy/com/muwire/core/EventBus.groovy index f3654fde..8f3bf331 100644 --- a/core/src/main/groovy/com/muwire/core/EventBus.groovy +++ b/core/src/main/groovy/com/muwire/core/EventBus.groovy @@ -31,9 +31,11 @@ class EventBus { synchronized(this) { currentHandlers = handlers.getOrDefault(clazz, []) } - currentHandlers.each { + for(def handler : currentHandlers) { + if (e.vetoed) + break try { - it."on${clazz.getSimpleName()}"(e) + handler."on${clazz.getSimpleName()}"(e) } catch (Exception bad) { log.log(Level.SEVERE, "exception dispatching event",bad) }