| 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</li> | |
| 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 | * </ul> | |
| 30 | */ | |
| 31 | public final class Context { | |
| 32 | ||
| 33 | public static final Context EMPTY = new Context(null, null); | |
| 34 | private 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) { | |
| 41 | this.executorService = executorService; | |
| 42 | this.constants = constants; | |
| 43 | actionQueueState = new ActionQueueState(); | |
| 44 | } | |
| 45 | ||
| 46 | public void setLogger(ILogger logger) { | |
| 47 | this.logger = logger; | |
| 48 | } | |
| 49 | ||
| 50 | public ILogger getLogger() { | |
| 51 |
1
1. getLogger : replaced return value with null for com/renomad/minum/state/Context::getLogger → KILLED |
return logger; |
| 52 | } | |
| 53 | ||
| 54 | public ExecutorService getExecutorService() { | |
| 55 |
1
1. getExecutorService : replaced return value with null for com/renomad/minum/state/Context::getExecutorService → KILLED |
return executorService; |
| 56 | } | |
| 57 | ||
| 58 | public Constants getConstants() { | |
| 59 |
1
1. getConstants : replaced return value with null for com/renomad/minum/state/Context::getConstants → KILLED |
return constants; |
| 60 | } | |
| 61 | ||
| 62 | public void setFullSystem(FullSystem fullSystem) { | |
| 63 | this.fullSystem = fullSystem; | |
| 64 | } | |
| 65 | ||
| 66 | public FullSystem getFullSystem() { | |
| 67 |
1
1. getFullSystem : replaced return value with null for com/renomad/minum/state/Context::getFullSystem → TIMED_OUT |
return fullSystem; |
| 68 | } | |
| 69 | ||
| 70 | public ActionQueueState getActionQueueState() { | |
| 71 |
1
1. getActionQueueState : replaced return value with null for com/renomad/minum/state/Context::getActionQueueState → KILLED |
return actionQueueState; |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * This is a helper method to instantiate a {@link Db} class, | |
| 76 | * avoiding the need for a user to provide the root database | |
| 77 | * directory and the context. | |
| 78 | * <p> | |
| 79 | * Since this is a generic method, a bit of care is required when | |
| 80 | * calling. Try to use a pattern like the following pseudocode: | |
| 81 | * {@snippet : | |
| 82 | * Db<Photograph> photoDb = context.getDb("photos", new Photograph()); | |
| 83 | * } | |
| 84 | * @param name the name of this data. Note that this will be used | |
| 85 | * as the directory for the data, so use characters your | |
| 86 | * operating system would allow. | |
| 87 | * @param instance an instance of the {@link DbData} data. This is used in the | |
| 88 | * Db code to deserialize the data when reading. | |
| 89 | */ | |
| 90 | public <T extends DbData<?>> Db<T> getDb(String name, T instance) { | |
| 91 |
1
1. getDb : replaced return value with null for com/renomad/minum/state/Context::getDb → TIMED_OUT |
return new Db<>(Path.of(constants.dbDirectory, name), this, instance); |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * This is a helper method to instantiate a {@link DbEngine2} class, | |
| 96 | * using the engine2 database implementation. It is similar to | |
| 97 | * {@link #getDb(String, DbData)} in all other respects. | |
| 98 | * <p> | |
| 99 | * By switching your old database calls to use this, when it runs | |
| 100 | * it will convert the file schema. | |
| 101 | * </p> | |
| 102 | * <p> | |
| 103 | * <b>Please backup your database before conversion</b> | |
| 104 | * </p> | |
| 105 | */ | |
| 106 | public <T extends DbData<?>> DbEngine2<T> getDb2(String name, T instance) { | |
| 107 |
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); |
| 108 | } | |
| 109 | ||
| 110 | ||
| 111 | } | |
Mutations | ||
| 51 |
1.1 |
|
| 55 |
1.1 |
|
| 59 |
1.1 |
|
| 67 |
1.1 |
|
| 71 |
1.1 |
|
| 91 |
1.1 |
|
| 107 |
1.1 |