Commenting
This commit is contained in:
@@ -19,10 +19,12 @@ public class AsyncEventLoop extends AdvancedEventLoop {
|
|||||||
Class<? extends Event> eventType = event.getClass();
|
Class<? extends Event> eventType = event.getClass();
|
||||||
|
|
||||||
if (handlers.containsKey(eventType)) {
|
if (handlers.containsKey(eventType)) {
|
||||||
|
// Create inter-thread state
|
||||||
List<ExecutorLink> handlerList = handlers.get(eventType);
|
List<ExecutorLink> handlerList = handlers.get(eventType);
|
||||||
EventBatch eventBatch = new EventBatch(handlerList.size());
|
EventBatch eventBatch = new EventBatch(handlerList.size());
|
||||||
CountDownLatch latch = new CountDownLatch(handlerList.size());
|
CountDownLatch latch = new CountDownLatch(handlerList.size());
|
||||||
|
|
||||||
|
// Submit all defined preprocessing methods as async tasks
|
||||||
for (int i = 0; i < handlerList.size(); i++) {
|
for (int i = 0; i < handlerList.size(); i++) {
|
||||||
if (handlerList.get(i).getPreprocessMethod() == null) {
|
if (handlerList.get(i).getPreprocessMethod() == null) {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
@@ -31,12 +33,15 @@ public class AsyncEventLoop extends AdvancedEventLoop {
|
|||||||
preEventExecutor.submit(new PreprocessTask(i, eventBatch, latch, handlerList.get(i), event));
|
preEventExecutor.submit(new PreprocessTask(i, eventBatch, latch, handlerList.get(i), event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Await for them to complete
|
||||||
try {
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Synchronously invoke EventHandlers with
|
||||||
|
// data obtained from EventBatch
|
||||||
for (int i = 0; i < handlerList.size(); i++) {
|
for (int i = 0; i < handlerList.size(); i++) {
|
||||||
ExecutorLink link = handlerList.get(i);
|
ExecutorLink link = handlerList.get(i);
|
||||||
if (link.isIgnoreCancelled() && event.isCanceled())
|
if (link.isIgnoreCancelled() && event.isCanceled())
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package mc.core.events.async;
|
package mc.core.events.async;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores state to pass from async executors to sync
|
||||||
|
*
|
||||||
|
* TODO: Change name, misleading
|
||||||
|
*/
|
||||||
public class EventBatch {
|
public class EventBatch {
|
||||||
private Object[] returnInject;
|
private Object[] returnInject;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user