nothing much

master
Ondřej Hruška 11 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
*/
public abstract class BusEvent<HANDLER> {
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<HANDLER> {
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<HANDLER> {
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<HANDLER> {
{
return consumed;
}
/**
* @return true if the event was served to at least 1 client
*/
@ -100,8 +102,8 @@ public abstract class BusEvent<HANDLER> {
{
return served;
}
/**
* Clear "served" and "consumed" flags before dispatching.
*/
@ -110,8 +112,8 @@ public abstract class BusEvent<HANDLER> {
served = false;
consumed = false;
}
/**
* Called after all clients have received the event.
*

Loading…
Cancel
Save