diff --git a/src/main/java/com/seibel/lod/core/util/DummyRunExecutorService.java b/src/main/java/com/seibel/lod/core/util/DummyRunExecutorService.java new file mode 100644 index 000000000..62e0aa8f7 --- /dev/null +++ b/src/main/java/com/seibel/lod/core/util/DummyRunExecutorService.java @@ -0,0 +1,133 @@ +package com.seibel.lod.core.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +public class DummyRunExecutorService implements ExecutorService { + private boolean shutdownCalled = false; + + @Override + public void execute(Runnable command) + { + command.run(); + } + + @Override + public void shutdown() + { + shutdownCalled = true; + } + + @Override + public List shutdownNow() + { + shutdownCalled = true; + return List.of(); + } + + @Override + public boolean isShutdown() + { + return shutdownCalled; + } + + @Override + public boolean isTerminated() + { + return shutdownCalled; + } + + @Override + public boolean awaitTermination(long timeout, TimeUnit unit) + { + shutdownCalled = true; + return true; + } + + @Override + public Future submit(Callable task) + { + try + { + return CompletableFuture.completedFuture(task.call()); + } + catch (Throwable e) + { + return CompletableFuture.failedFuture(e); + } + } + + @Override + public Future submit(Runnable task, T result) + { + try + { + task.run(); + return CompletableFuture.completedFuture(result); + } + catch (Throwable e) + { + return CompletableFuture.failedFuture(e); + } + } + + @Override + public Future submit(Runnable task) + { + try + { + task.run(); + return CompletableFuture.completedFuture(null); + } + catch (Throwable e) + { + return CompletableFuture.failedFuture(e); + } + } + + @Override + public List> invokeAll(Collection> tasks) + { + List> futures = new ArrayList>(tasks.size()); + for (Callable t : tasks) { + futures.add(submit(t)); + } + return futures; + } + + @Override + public List> invokeAll(Collection> tasks, long timeout, TimeUnit unit) + { + return invokeAll(tasks); + } + + @Override + public T invokeAny(Collection> tasks) throws ExecutionException + { + Throwable latestE = null; + for (Callable t : tasks) { + try { + return t.call(); + } + catch (Throwable e) + { + latestE = e; + } + } + throw new ExecutionException(latestE); + } + + @Override + public T invokeAny(Collection> tasks, long timeout, TimeUnit unit) throws ExecutionException + { + return invokeAny(tasks); + } + +} \ No newline at end of file