From 272fb631684b1d05c47007eec5a1ea596dffe5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 29 Jul 2014 04:07:22 +0200 Subject: [PATCH] nothing much --- src/mightypork/utils/eventbus/BusEvent.java | 38 +++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/mightypork/utils/eventbus/BusEvent.java b/src/mightypork/utils/eventbus/BusEvent.java index aba4f5e..ff21d52 100644 --- a/src/mightypork/utils/eventbus/BusEvent.java +++ b/src/mightypork/utils/eventbus/BusEvent.java @@ -31,19 +31,19 @@ import mightypork.utils.eventbus.events.flags.SingleReceiverEvent; * @param handler type */ public abstract class BusEvent { - + private boolean consumed; private boolean served; - - + + /** * Ask handler to handle this message. * * @param handler handler instance */ protected abstract void handleBy(HANDLER handler); - - + + /** * Consume the event, so no other clients will receive it. * @@ -53,15 +53,17 @@ public abstract class BusEvent { public final void consume() { if (consumed) throw new IllegalStateException("Already consumed."); - + if (getClass().isAnnotationPresent(NonConsumableEvent.class)) { throw new UnsupportedOperationException("Not consumable."); } + (new Throwable()).printStackTrace(); + consumed = true; } - - + + /** * Deliver to a handler using the handleBy method. * @@ -70,17 +72,17 @@ public abstract class BusEvent { final void deliverTo(HANDLER handler) { handleBy(handler); - + if (!served) { if (getClass().isAnnotationPresent(SingleReceiverEvent.class)) { consumed = true; } - + served = true; } } - - + + /** * Check if the event is consumed. When an event is consumed, no other * clients will receive it. @@ -91,8 +93,8 @@ public abstract class BusEvent { { return consumed; } - - + + /** * @return true if the event was served to at least 1 client */ @@ -100,8 +102,8 @@ public abstract class BusEvent { { return served; } - - + + /** * Clear "served" and "consumed" flags before dispatching. */ @@ -110,8 +112,8 @@ public abstract class BusEvent { served = false; consumed = false; } - - + + /** * Called after all clients have received the event. *