Archived
0

Commenting

This commit is contained in:
Daniil
2018-07-26 11:18:42 +07:00
parent 190749b739
commit abae528d0b
2 changed files with 10 additions and 0 deletions

View File

@@ -19,10 +19,12 @@ public class AsyncEventLoop extends AdvancedEventLoop {
Class<? extends Event> eventType = event.getClass();
if (handlers.containsKey(eventType)) {
// Create inter-thread state
List<ExecutorLink> handlerList = handlers.get(eventType);
EventBatch eventBatch = new EventBatch(handlerList.size());
CountDownLatch latch = new CountDownLatch(handlerList.size());
// Submit all defined preprocessing methods as async tasks
for (int i = 0; i < handlerList.size(); i++) {
if (handlerList.get(i).getPreprocessMethod() == null) {
latch.countDown();
@@ -31,12 +33,15 @@ public class AsyncEventLoop extends AdvancedEventLoop {
preEventExecutor.submit(new PreprocessTask(i, eventBatch, latch, handlerList.get(i), event));
}
// Await for them to complete
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
// Synchronously invoke EventHandlers with
// data obtained from EventBatch
for (int i = 0; i < handlerList.size(); i++) {
ExecutorLink link = handlerList.get(i);
if (link.isIgnoreCancelled() && event.isCanceled())

View File

@@ -1,5 +1,10 @@
package mc.core.events.async;
/**
* Stores state to pass from async executors to sync
*
* TODO: Change name, misleading
*/
public class EventBatch {
private Object[] returnInject;