|
| 1 | +# Module Scheduler |
| 2 | + |
| 3 | +[](https://search.maven.org/search?q=g:%22nl.devoxist%22%20AND%20a:%22module-scheduler%22) |
| 4 | +[](https://github.com/Devoxist/module-scheduler/blob/master/LICENSE) |
| 5 | + |
| 6 | +### Getting Started |
| 7 | + |
| 8 | +How to install this API? For all possible options to install this API [maven |
| 9 | +central](https://search.maven.org/artifact/nl.devoxist/module-scheduler) and select the version. |
| 10 | + |
| 11 | +#### Maven |
| 12 | + |
| 13 | +Add this to your `pom.xml`. |
| 14 | + |
| 15 | +```xml |
| 16 | + |
| 17 | +<dependency> |
| 18 | + <groupId>nl.devoxist</groupId> |
| 19 | + <artifactId>module-scheduler</artifactId> |
| 20 | + <version>1.0.0</version> |
| 21 | +</dependency> |
| 22 | +``` |
| 23 | + |
| 24 | +### Usage |
| 25 | + |
| 26 | +This API can be used to automatically order tasks/modules in the correct order. |
| 27 | + |
| 28 | +### How to use this API? |
| 29 | + |
| 30 | +Firstly create as class that implements `ModuleScheduler`. This is the controller of all the modules. |
| 31 | + |
| 32 | +```java |
| 33 | +public class ModuleSchedulerProcess implements ModuleScheduler { |
| 34 | + |
| 35 | + @Override |
| 36 | + public void updateSettings(@NotNull ModuleSchedulerSettings settings) { |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + @Override |
| 41 | + public void beforeModuleExecute(Module module) { |
| 42 | + // Put here your stuff |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public void afterModuleExecute(Module module) { |
| 47 | + // Put here your stuff |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +Then you want to add some modules to the controllers. The modules can be created by implementing `Module`. |
| 53 | + |
| 54 | +```java |
| 55 | +public class ModuleA implements Module { |
| 56 | + |
| 57 | + @Override |
| 58 | + public void onExecute() { |
| 59 | + // Put here your stuff |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +To mark a dependency link to another module use the `@Dependency` annotation above the class of the `Module`. This |
| 65 | +annotation is needed to order the Modules. |
| 66 | + |
| 67 | +```java |
| 68 | + |
| 69 | +@Dependency(ModuleA.class) |
| 70 | +public class ModuleB implements Module { |
| 71 | + |
| 72 | + public ModuleB(ModuleA moduleA) { |
| 73 | + // Put here your stuff |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + @Override |
| 78 | + public void onExecute() { |
| 79 | + // Put here your stuff |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +To mark a multiple dependency links to another module use the `@Dependency` annotation above the class of the `Module`. |
| 85 | +This annotation is needed to order the Modules. |
| 86 | + |
| 87 | +```java |
| 88 | + |
| 89 | +@Dependency({ModuleB.class, ModuleA.class}) |
| 90 | +public class ModuleC implements Module { |
| 91 | + |
| 92 | + public ModuleC(ModuleA moduleA, ModuleB moduleB) { |
| 93 | + // Put here your stuff |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void onExecute() { |
| 98 | + // Put here your stuff |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +How to add modules to the controller, the scheduler? This can be done to change the content of the |
| 104 | +method, `ModuleScheduler#updateSettings`. Add a line with `ModuleSchedulerSettings#addModule`. It is important to add |
| 105 | +all the tasks/modules that need to be loaded. Only the modules that are added can be loaded. |
| 106 | + |
| 107 | +```java |
| 108 | + @Override |
| 109 | + public void updateSettings(@NotNull ModuleSchedulerSettings settings){ |
| 110 | + settings.addModule(ModuleA.class); |
| 111 | + settings.addModule(ModuleB.class); |
| 112 | + settings.addModule(ModuleC.class); |
| 113 | + } |
| 114 | +``` |
| 115 | + |
| 116 | +How to start the process? Construct the `Scheduler` class with the inherited `ModuleScheduler` that you want to load. |
| 117 | +After calling this construction the modules will automatically be runned in correct order. These methods will run, when |
| 118 | +a module is being executed, in the following |
| 119 | +order `ModuleScheduler#beforeModuleExecute` -> `Module#onExecute` -> `ModuleScheduler#afterModuleExecute`. |
| 120 | + |
| 121 | +```java |
| 122 | +new Scheduler(new ModuleSchedulerProcess()); |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | +### Contributors |
| 127 | + |
| 128 | ++ Dev-Bjorn |
0 commit comments