| 1 | package com.renomad.minum.state; | |
| 2 | ||
| 3 | import com.renomad.minum.database.Db; | |
| 4 | import com.renomad.minum.database.DbData; | |
| 5 | import com.renomad.minum.database.DbEngine2; | |
| 6 | import com.renomad.minum.logging.ILogger; | |
| 7 | import com.renomad.minum.queue.ActionQueueState; | |
| 8 | import com.renomad.minum.web.FullSystem; | |
| 9 | ||
| 10 | import java.nio.file.Path; | |
| 11 | import java.util.concurrent.ExecutorService; | |
| 12 | ||
| 13 | ||
| 14 | /** | |
| 15 | * Holds important system-wide data and methods, such as the | |
| 16 | * logger, constants, and the {@link FullSystem} instance. | |
| 17 | * <p> | |
| 18 | * The common situations: | |
| 19 | * </p> | |
| 20 | * <ul> | |
| 21 | * <li>Building a Minum {@link Db} database</li> | |
| 22 | * <li>Getting system constants like the database directory</li> | |
| 23 | * <li>Getting the system {@link ExecutorService} for starting threads or an {@link com.renomad.minum.queue.ActionQueue}</li> | |
| 24 | * <li>Getting a {@link FullSystem} object, which has | |
| 25 | * <ul> | |
| 26 | * <li>the {@link com.renomad.minum.web.WebFramework}, which registers endpoints</li> | |
| 27 | * <li>the {@link com.renomad.minum.security.TheBrig}, which handles bad actors on the internet</li> | |
| 28 | * </ul> | |
| 29 | * </li> | |
| 30 | * </ul> | |
| 31 | */ | |
| 32 | public final class Context { | |
| 33 | ||
| 34 | private final ILogger logger; | |
| 35 | private final ExecutorService executorService; | |
| 36 | private final Constants constants; | |
| 37 | private FullSystem fullSystem; | |
| 38 | private final ActionQueueState actionQueueState; | |
| 39 | ||
| 40 | public Context(ExecutorService executorService, Constants constants, ILogger logger) { | |
| 41 | this.executorService = executorService; | |
| 42 | this.constants = constants; | |
| 43 | actionQueueState = new ActionQueueState(); | |
| 44 | this.logger = logger; | |
| 45 | } | |
| 46 | ||
| 47 | public ILogger getLogger() { | |
| 48 |
1
1. getLogger : replaced return value with null for com/renomad/minum/state/Context::getLogger → KILLED |
return logger; |
| 49 | } | |
| 50 | ||
| 51 | public ExecutorService getExecutorService() { | |
| 52 |
1
1. getExecutorService : replaced return value with null for com/renomad/minum/state/Context::getExecutorService → KILLED |
return executorService; |
| 53 | } | |
| 54 | ||
| 55 | public Constants getConstants() { | |
| 56 |
1
1. getConstants : replaced return value with null for com/renomad/minum/state/Context::getConstants → KILLED |
return constants; |
| 57 | } | |
| 58 | ||
| 59 | public void setFullSystem(FullSystem fullSystem) { | |
| 60 | this.fullSystem = fullSystem; | |
| 61 | } | |
| 62 | ||
| 63 | public FullSystem getFullSystem() { | |
| 64 |
1
1. getFullSystem : replaced return value with null for com/renomad/minum/state/Context::getFullSystem → TIMED_OUT |
return fullSystem; |
| 65 | } | |
| 66 | ||
| 67 | public ActionQueueState getActionQueueState() { | |
| 68 |
1
1. getActionQueueState : replaced return value with null for com/renomad/minum/state/Context::getActionQueueState → KILLED |
return actionQueueState; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * This is a helper method to instantiate a {@link Db} class, | |
| 73 | * avoiding the need for a user to provide the root database | |
| 74 | * directory and the context. | |
| 75 | * <p> | |
| 76 | * Since this is a generic method, a bit of care is required when | |
| 77 | * calling. Try to use a pattern like the following pseudocode: | |
| 78 | * {@snippet : | |
| 79 | * Db<Photograph> photoDb = context.getDb("photos", new Photograph()); | |
| 80 | * } | |
| 81 | * @param name the name of this data. Note that this will be used | |
| 82 | * as the directory for the data, so use characters your | |
| 83 | * operating system would allow. | |
| 84 | * @param instance an instance of the {@link DbData} data. This is used in the | |
| 85 | * Db code to deserialize the data when reading. | |
| 86 | */ | |
| 87 | public <T extends DbData<?>> Db<T> getDb(String name, T instance) { | |
| 88 |
1
1. getDb : replaced return value with null for com/renomad/minum/state/Context::getDb → KILLED |
return new Db<>(Path.of(constants.dbDirectory, name), this, instance); |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * This is a helper method to instantiate a {@link DbEngine2} class, | |
| 93 | * using the engine2 database implementation. It is similar to | |
| 94 | * {@link #getDb(String, DbData)} in all other respects. | |
| 95 | * <p> | |
| 96 | * By switching your old database calls to use this, when it runs | |
| 97 | * it will convert the file schema. | |
| 98 | * </p> | |
| 99 | * <p> | |
| 100 | * <b>Please backup your database before conversion</b> | |
| 101 | * </p> | |
| 102 | */ | |
| 103 | public <T extends DbData<?>> DbEngine2<T> getDb2(String name, T instance) { | |
| 104 |
1
1. getDb2 : replaced return value with null for com/renomad/minum/state/Context::getDb2 → KILLED |
return new DbEngine2<>(Path.of(constants.dbDirectory, name), this, instance); |
| 105 | } | |
| 106 | ||
| 107 | ||
| 108 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 52 |
1.1 |
|
| 56 |
1.1 |
|
| 64 |
1.1 |
|
| 68 |
1.1 |
|
| 88 |
1.1 |
|
| 104 |
1.1 |