package net.mostlyoriginal.api.event.dispatcher;

import net.mostlyoriginal.api.event.common.Event;

import com.artemis.utils.Bag;

/**
 * Polling event dispatcher.
 * 
 * @author Namek
 */
public class PollingEventDispatcher extends FastEventDispatcher {
	private final Bag<Event> eventQueue = new Bag<Event>();
	
	@Override
	public void process() {
		Object[] eventsToDispatch = eventQueue.getData();
		
		for (int i = 0, s = eventQueue.size(); i < s; i++) {
			Event event = (Event) eventsToDispatch[i];
			super.dispatch(event);
		}
		
		eventQueue.clear();
	}
	
	public void dispatch(Event event) {
		eventQueue.add(event);
	}
}

@@ -128,16 +128,122 @@
 ls.Bag;%0D
+%0Aimport com.artemis.utils.reflect.ClassReflection;%0D%0Aimport com.artemis.utils.reflect.ReflectionException;%0D
 %0A%0D%0A/**%0D%0A
@@ -760,11 +760,366 @@
 );%0D%0A%09%7D%0D%0A
+%09%0D%0A%09@Override%0D%0A%09public %3CT extends Event%3E T dispatch(Class%3CT%3E type) %7B%0D%0A%09%09T event;%0D%0A%09%09try %7B%0D%0A%09%09%09event = (T)ClassReflection.newInstance(type);%0D%0A%09%09%09this.dispatch(event);%0D%0A%09%09%7D%0D%0A%09%09catch (ReflectionException e) %7B%0D%0A%09%09%09String error = %22Couldn't instantiate object of type %22 + type.getName();%0D%0A%09%09%09throw new RuntimeException(error, e);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09return event;%0D%0A%09%7D%0D%0A
 %7D%0D%0A

Add convenient method to not throw exception. It's much easier to switch between PollingEventDispatcher and PollingPooledEventDispatcher.