aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/Main.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-04-14 18:03:32 -0700
committerAnton Tananaev <anton@traccar.org>2022-04-14 18:03:32 -0700
commit437a7651096ecdd8e9cabeeca760b9af89b10458 (patch)
tree158176e6025fbf12e28140cc8068fd66055cb1e0 /src/main/java/org/traccar/Main.java
parent3241b83dc95fa151ac66dd88c102f08cc7cfaa7a (diff)
downloadtrackermap-server-437a7651096ecdd8e9cabeeca760b9af89b10458.tar.gz
trackermap-server-437a7651096ecdd8e9cabeeca760b9af89b10458.tar.bz2
trackermap-server-437a7651096ecdd8e9cabeeca760b9af89b10458.zip
Refactor services
Diffstat (limited to 'src/main/java/org/traccar/Main.java')
-rw-r--r--src/main/java/org/traccar/Main.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/Main.java b/src/main/java/org/traccar/Main.java
index 63e5c1f90..570f3c6ad 100644
--- a/src/main/java/org/traccar/Main.java
+++ b/src/main/java/org/traccar/Main.java
@@ -27,6 +27,9 @@ import java.lang.management.MemoryMXBean;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Locale;
import java.util.Timer;
@@ -123,11 +126,16 @@ public final class Main {
LOGGER.info("Version: " + Main.class.getPackage().getImplementationVersion());
LOGGER.info("Starting server...");
- Context.getServerManager().start();
+ List<LifecycleObject> services = new LinkedList<>();
+ services.add(Context.getServerManager());
if (Context.getWebServer() != null) {
- Context.getWebServer().start();
+ services.add(Context.getWebServer());
+ }
+ services.add(Context.getScheduleManager());
+
+ for (LifecycleObject service : services) {
+ service.start();
}
- Context.getScheduleManager().start();
scheduleHealthCheck();
@@ -136,11 +144,10 @@ public final class Main {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOGGER.info("Shutting down server...");
- Context.getScheduleManager().stop();
- if (Context.getWebServer() != null) {
- Context.getWebServer().stop();
+ Collections.reverse(services);
+ for (LifecycleObject service : services) {
+ service.stop();
}
- Context.getServerManager().stop();
}));
} catch (Exception e) {
LOGGER.error("Main method error", e);