|
|
|
@ -6,9 +6,9 @@ import java.util.concurrent.Delayed; |
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
import mightypork.utils.control.bus.events.Event; |
|
|
|
|
import mightypork.utils.control.bus.events.types.DelayedEvent; |
|
|
|
|
import mightypork.utils.control.bus.events.types.ImmediateEvent; |
|
|
|
|
import mightypork.utils.control.bus.events.types.QueuedEvent; |
|
|
|
|
import mightypork.utils.control.bus.events.types.SingularEvent; |
|
|
|
|
import mightypork.utils.control.bus.events.types.SingleReceiverEvent; |
|
|
|
|
import mightypork.utils.control.interf.Destroyable; |
|
|
|
|
import mightypork.utils.logging.Log; |
|
|
|
|
|
|
|
|
@ -27,7 +27,7 @@ final public class EventBus implements Destroyable { |
|
|
|
|
private final BufferedHashSet<Object> clients = new BufferedHashSet<Object>(); |
|
|
|
|
|
|
|
|
|
/** Messages queued for delivery */ |
|
|
|
|
private final DelayQueue<DelayedEvent> sendQueue = new DelayQueue<DelayedEvent>(); |
|
|
|
|
private final DelayQueue<DelayQueueEntry> sendQueue = new DelayQueue<DelayQueueEntry>(); |
|
|
|
|
|
|
|
|
|
/** Queue polling thread */ |
|
|
|
|
private final QueuePollingThread busThread; |
|
|
|
@ -110,8 +110,9 @@ final public class EventBus implements Destroyable { |
|
|
|
|
{ |
|
|
|
|
assertLive(); |
|
|
|
|
|
|
|
|
|
if(event.getClass().isAnnotationPresent(QueuedEvent.class)) { |
|
|
|
|
sendQueued(event); |
|
|
|
|
DelayedEvent adelay = event.getClass().getAnnotation(DelayedEvent.class); |
|
|
|
|
if (adelay != null) { |
|
|
|
|
sendDelayed(event, adelay.delay()); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -120,7 +121,7 @@ final public class EventBus implements Destroyable { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dispatch(event); |
|
|
|
|
sendQueued(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -147,7 +148,7 @@ final public class EventBus implements Destroyable { |
|
|
|
|
{ |
|
|
|
|
assertLive(); |
|
|
|
|
|
|
|
|
|
final DelayedEvent dm = new DelayedEvent(delay, event); |
|
|
|
|
final DelayQueueEntry dm = new DelayQueueEntry(delay, event); |
|
|
|
|
|
|
|
|
|
if (logSending) Log.f3("<bus> Q " + Log.str(event) + ", t = +" + delay + "s"); |
|
|
|
|
|
|
|
|
@ -190,7 +191,7 @@ final public class EventBus implements Destroyable { |
|
|
|
|
boolean sent = false; |
|
|
|
|
boolean accepted = false; |
|
|
|
|
|
|
|
|
|
final boolean singular = event.getClass().isAnnotationPresent(SingularEvent.class); |
|
|
|
|
final boolean singular = event.getClass().isAnnotationPresent(SingleReceiverEvent.class); |
|
|
|
|
|
|
|
|
|
for (final EventChannel<?, ?> b : channels) { |
|
|
|
|
if (b.canBroadcast(event)) { |
|
|
|
@ -253,13 +254,13 @@ final public class EventBus implements Destroyable { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class DelayedEvent implements Delayed { |
|
|
|
|
private class DelayQueueEntry implements Delayed { |
|
|
|
|
|
|
|
|
|
private final long due; |
|
|
|
|
private Event<?> evt = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DelayedEvent(double seconds, Event<?> event) { |
|
|
|
|
public DelayQueueEntry(double seconds, Event<?> event) { |
|
|
|
|
super(); |
|
|
|
|
this.due = System.currentTimeMillis() + (long) (seconds * 1000); |
|
|
|
|
this.evt = event; |
|
|
|
@ -300,7 +301,7 @@ final public class EventBus implements Destroyable { |
|
|
|
|
@Override |
|
|
|
|
public void run() |
|
|
|
|
{ |
|
|
|
|
DelayedEvent evt; |
|
|
|
|
DelayQueueEntry evt; |
|
|
|
|
|
|
|
|
|
while (!stopped) { |
|
|
|
|
evt = null; |
|
|
|
|