@@ -0,0 +1,3512 @@
+/*%0A * The MIT License (MIT)%0A *%0A * Copyright (c) 2015 Lachlan Dowding%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in all%0A * copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0A * SOFTWARE.%0A */%0A%0Apackage permafrost.tundra.util.concurrent;%0A%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.concurrent.AbstractExecutorService;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0A%0A/**%0A * An ExecutorService implementation which runs commands immediately on the current thread.%0A */%0Apublic class DirectExecutorService extends AbstractExecutorService %7B%0A    /**%0A     * Whether the service has been shut down.%0A     */%0A    protected AtomicBoolean isShutdown = new AtomicBoolean(false);%0A%0A    /**%0A     * Returns true if this executor has been shut down.%0A     *%0A     * @return True if this executor has been shut down.%0A     */%0A    @Override%0A    public boolean isShutdown() %7B%0A        return isShutdown.get();%0A    %7D%0A%0A    /**%0A     * Returns true if all tasks have completed following shut down. Note that isTerminated is never%0A     * true unless either shutdown or shutdownNow was called first.%0A     *%0A     * @return True if all tasks have completed following shut down.%0A     */%0A    @Override%0A    public boolean isTerminated() %7B%0A        return isShutdown.get();%0A    %7D%0A%0A    /**%0A     * Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs,%0A     * or the current thread is interrupted, whichever happens first.%0A     *%0A     * @param timeout The maximum time to wait.%0A     * @param unit    The time unit of the timeout argument.%0A     * @return        True if this executor terminated and false if the timeout elapsed before termination.%0A     * @throws InterruptedException If interrupted while waiting.%0A     */%0A    @Override%0A    public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException %7B%0A        return isShutdown.get();%0A    %7D%0A%0A    /**%0A     * Shuts down the service immediately.%0A     *%0A     * @return The list of tasks that never commenced execution; always empty.%0A     */%0A    @Override%0A    public List%3CRunnable%3E shutdownNow() %7B%0A        shutdown();%0A        return new LinkedList%3CRunnable%3E();%0A    %7D%0A%0A    /**%0A     * Shuts down the service.%0A     */%0A    @Override%0A    public void shutdown() %7B%0A        isShutdown.set(true);%0A    %7D%0A%0A    /**%0A     * Executes the given command immediately in the current thread.%0A     *%0A     * @param command The runnable task.%0A     */%0A    @Override%0A    public void execute(Runnable command) %7B%0A        command.run();%0A    %7D%0A%7D%0A

Add DirectExecutorService for running commands immediately on the current thread