Archived
0

Completed some TODOs

This commit is contained in:
Daniil
2018-08-03 21:03:32 +07:00
parent c5c5acee8f
commit 38f69c3dfa
3 changed files with 16 additions and 15 deletions

View File

@@ -38,25 +38,27 @@ public class EventPipeline {
} }
RegisteredEventHandler handler = handlers.get(currentIndex); RegisteredEventHandler handler = handlers.get(currentIndex);
service.addTask(new ResourceRunnable() { if (!event.isCanceled() || !handler.isIgnoreCancelled()) {
@Override service.addTask(new ResourceRunnable() {
public void run() { @Override
// TODO: Do we really need to process this in an async thread? public void run() {
if (!event.isCanceled() || !handler.isIgnoreCancelled()) {
try { try {
handler.getMethod().invoke(handler.getObject(), event); handler.getMethod().invoke(handler.getObject(), event);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
log.error("Unable to dispatch event " + event.getClass().getSimpleName() + " to handler " + event.getClass().getName(), e); log.error("Unable to dispatch event " + event.getClass().getSimpleName() + " to handler " + event.getClass().getName(), e);
} }
} }
}
@Override @Override
public void after() { public void after() {
currentIndex++; currentIndex++;
next(service); next(service);
} }
}); });
} else {
currentIndex++;
next(service);
}
} }
public enum PipelineState { public enum PipelineState {

View File

@@ -97,7 +97,6 @@ public class FullAsyncEventLoop {
} }
if (queue.peek().getState() == EventPipeline.PipelineState.FINISHED) { if (queue.peek().getState() == EventPipeline.PipelineState.FINISHED) {
// TODO: Post-event callback?
queue.poll(); queue.poll();
} }

View File

@@ -9,6 +9,7 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
public class EventExecutorService { public class EventExecutorService {
private static final boolean WORKER_INSTANT_EXECUTE = false;
private BlockingQueue<ResourceRunnable> queue = new ArrayBlockingQueue<>(100); private BlockingQueue<ResourceRunnable> queue = new ArrayBlockingQueue<>(100);
private ScheduleStrategy strategy = new DefaultScheduleStrategy(); private ScheduleStrategy strategy = new DefaultScheduleStrategy();
private Set<Thread> executorThreads = new HashSet<>(); private Set<Thread> executorThreads = new HashSet<>();
@@ -42,8 +43,7 @@ public class EventExecutorService {
} }
public void addTask(ResourceRunnable task) { public void addTask(ResourceRunnable task) {
if (Thread.currentThread() instanceof ExecutorThread) { if (WORKER_INSTANT_EXECUTE && Thread.currentThread() instanceof ExecutorThread) {
// TODO: Do we really need instant execution?
((ExecutorThread) Thread.currentThread()).executeTask(task); ((ExecutorThread) Thread.currentThread()).executeTask(task);
} else } else
queue.offer(task); queue.offer(task);