Repository navigation
Expand file tree
/
Copy pathAutoSetup.java
More file actions
72 lines (61 loc) · 1.97 KB
/
Copy pathAutoSetup.java
File metadata and controls
72 lines (61 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Made with all the love in the world
* by scireum in Stuttgart, Germany
*
* Copyright by scireum GmbH
* https://www.scireum.de - info@scireum.de
*/
package sirius.kernel;
import sirius.kernel.di.std.ConfigValue;
import sirius.kernel.di.std.PriorityParts;
import sirius.kernel.di.std.Register;
import sirius.kernel.health.Exceptions;
import sirius.kernel.health.Log;
import java.util.List;
/**
* Responsible for executing {@link AutoSetupRule auto setup rules} during th system startup.
* <p>
* As most probably we only want to do this in dev / test / staging systems or once for production systems,
* this facility has to be enabled via the system config in <tt>sirius.autoSetup</tt>.
*/
@Register(classes = {AutoSetup.class, Startable.class})
public class AutoSetup implements Startable {
@ConfigValue("sirius.autoSetup")
private boolean enabled;
@PriorityParts(AutoSetupRule.class)
private List<AutoSetupRule> rules;
/**
* Represents the logger used for everything concerning the system setup
*/
public static final Log LOG = Log.get("autosetup");
@Override
public int getPriority() {
return 1000;
}
@Override
public void started() {
if (!isEnabled()) {
return;
}
for (AutoSetupRule rule : rules) {
LOG.INFO("Executing auto setup rule: %s", rule.getClass().getName());
try {
rule.setup();
} catch (Exception exception) {
Exceptions.handle()
.to(LOG)
.error(exception)
.withSystemErrorMessage("Auto seatup rule %s failed: %s (%s)", rule.getClass().getName())
.handle();
}
}
}
/**
* Determines if the auto setup facility is active.
*
* @return <tt>true</tt> if auto setup is enabled, <tt>false</tt> otherwise
*/
public boolean isEnabled() {
return enabled;
}
}