| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SynchronousExecutorManager |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * This file is part of AceLogger. | |
| 3 | * | |
| 4 | * AceLogger is free software: you can redistribute it and/or modify it under the terms of the GNU | |
| 5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of | |
| 6 | * the License, or (at your option) any later version. | |
| 7 | * | |
| 8 | * AceLogger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | |
| 9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 10 | * Lesser General Public License for more details. | |
| 11 | * | |
| 12 | * You should have received a copy of the GNU Lesser General Public License along with AceLogger. | |
| 13 | * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>. | |
| 14 | */ | |
| 15 | package net.sourceforge.acelogger.execution.manager; | |
| 16 | ||
| 17 | import java.util.Collections; | |
| 18 | import java.util.List; | |
| 19 | ||
| 20 | /** | |
| 21 | * An implementation of {@link ExecutorManager} that executes tasks synchronously in the same | |
| 22 | * caller's thread. | |
| 23 | * | |
| 24 | * @author Zardi (https://sourceforge.net/users/daniel_zardi) | |
| 25 | * @version 1.0.0 | |
| 26 | * @since 1.0.0 | |
| 27 | */ | |
| 28 | public class SynchronousExecutorManager extends BaseExecutorManager { | |
| 29 | ||
| 30 | /** | |
| 31 | * Indicates if this executor manager was shutdown or not. | |
| 32 | */ | |
| 33 | private boolean shutdown; | |
| 34 | ||
| 35 | /** | |
| 36 | * Constructs a new SynchronousExecutorManager with the supplied identifier. | |
| 37 | * | |
| 38 | * @param identifier | |
| 39 | * A string that identifies this executor manager. | |
| 40 | * @since 1.0.0 | |
| 41 | */ | |
| 42 | public SynchronousExecutorManager(String identifier) { | |
| 43 | 0 | super(identifier); |
| 44 | 0 | shutdown = false; |
| 45 | 0 | } |
| 46 | ||
| 47 | /** {@inheritDoc} */ | |
| 48 | public void execute(Runnable command) { | |
| 49 | 0 | command.run(); |
| 50 | 0 | } |
| 51 | ||
| 52 | /** {@inheritDoc} */ | |
| 53 | public boolean isTerminated() { | |
| 54 | 1 | return shutdown; |
| 55 | } | |
| 56 | ||
| 57 | /** {@inheritDoc} */ | |
| 58 | public boolean orderProperShutdown() { | |
| 59 | 1 | shutdown = true; |
| 60 | 1 | return shutdown; |
| 61 | } | |
| 62 | ||
| 63 | /** {@inheritDoc} */ | |
| 64 | public boolean awaitTermination(long terminationTimeout) { | |
| 65 | // TODO: should this check for a illegal state? this can be called only after shutdown | |
| 66 | 0 | return true; |
| 67 | } | |
| 68 | ||
| 69 | /** {@inheritDoc} */ | |
| 70 | public List<Runnable> terminateAndRetrieveTasks() { | |
| 71 | // TODO: should this check for a illegal state? this can be called only after shutdown | |
| 72 | 0 | return Collections.emptyList(); |
| 73 | } | |
| 74 | ||
| 75 | } |