nothing much

master
Ondřej Hruška 10 years ago
parent c5fcb49e78
commit 272fb63168
  1. 38
      src/mightypork/utils/eventbus/BusEvent.java

@ -31,19 +31,19 @@ import mightypork.utils.eventbus.events.flags.SingleReceiverEvent;
* @param <HANDLER> handler type * @param <HANDLER> handler type
*/ */
public abstract class BusEvent<HANDLER> { public abstract class BusEvent<HANDLER> {
private boolean consumed; private boolean consumed;
private boolean served; private boolean served;
/** /**
* Ask handler to handle this message. * Ask handler to handle this message.
* *
* @param handler handler instance * @param handler handler instance
*/ */
protected abstract void handleBy(HANDLER handler); protected abstract void handleBy(HANDLER handler);
/** /**
* Consume the event, so no other clients will receive it. * Consume the event, so no other clients will receive it.
* *
@ -53,15 +53,17 @@ public abstract class BusEvent<HANDLER> {
public final void consume() public final void consume()
{ {
if (consumed) throw new IllegalStateException("Already consumed."); if (consumed) throw new IllegalStateException("Already consumed.");
if (getClass().isAnnotationPresent(NonConsumableEvent.class)) { if (getClass().isAnnotationPresent(NonConsumableEvent.class)) {
throw new UnsupportedOperationException("Not consumable."); throw new UnsupportedOperationException("Not consumable.");
} }
(new Throwable()).printStackTrace();
consumed = true; consumed = true;
} }
/** /**
* Deliver to a handler using the handleBy method. * Deliver to a handler using the handleBy method.
* *
@ -70,17 +72,17 @@ public abstract class BusEvent<HANDLER> {
final void deliverTo(HANDLER handler) final void deliverTo(HANDLER handler)
{ {
handleBy(handler); handleBy(handler);
if (!served) { if (!served) {
if (getClass().isAnnotationPresent(SingleReceiverEvent.class)) { if (getClass().isAnnotationPresent(SingleReceiverEvent.class)) {
consumed = true; consumed = true;
} }
served = true; served = true;
} }
} }
/** /**
* Check if the event is consumed. When an event is consumed, no other * Check if the event is consumed. When an event is consumed, no other
* clients will receive it. * clients will receive it.
@ -91,8 +93,8 @@ public abstract class BusEvent<HANDLER> {
{ {
return consumed; return consumed;
} }
/** /**
* @return true if the event was served to at least 1 client * @return true if the event was served to at least 1 client
*/ */
@ -100,8 +102,8 @@ public abstract class BusEvent<HANDLER> {
{ {
return served; return served;
} }
/** /**
* Clear "served" and "consumed" flags before dispatching. * Clear "served" and "consumed" flags before dispatching.
*/ */
@ -110,8 +112,8 @@ public abstract class BusEvent<HANDLER> {
served = false; served = false;
consumed = false; consumed = false;
} }
/** /**
* Called after all clients have received the event. * Called after all clients have received the event.
* *

Loading…
Cancel
Save