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