aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/Main.java')
-rw-r--r--src/main/java/org/traccar/Main.java32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/main/java/org/traccar/Main.java b/src/main/java/org/traccar/Main.java
index c35ea33a9..412ac1f5e 100644
--- a/src/main/java/org/traccar/Main.java
+++ b/src/main/java/org/traccar/Main.java
@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.broadcast.BroadcastService;
import org.traccar.schedule.ScheduleManager;
+import org.traccar.web.WebServer;
import java.io.File;
import java.lang.management.ManagementFactory;
@@ -29,10 +30,10 @@ 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.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
public final class Main {
@@ -119,28 +120,23 @@ public final class Main {
LOGGER.info("Version: " + Main.class.getPackage().getImplementationVersion());
LOGGER.info("Starting server...");
- List<LifecycleObject> services = new LinkedList<>();
- services.add(injector.getInstance(ServerManager.class));
- services.add(Context.getWebServer());
- services.add(injector.getInstance(ScheduleManager.class));
- services.add(injector.getInstance(BroadcastService.class));
+ var services = Stream.of(
+ ServerManager.class, WebServer.class, ScheduleManager.class, BroadcastService.class)
+ .map(injector::getInstance)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
- for (LifecycleObject service : services) {
- if (service != null) {
- service.start();
- }
+ for (var service : services) {
+ service.start();
}
Thread.setDefaultUncaughtExceptionHandler((t, e) -> LOGGER.error("Thread exception", e));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- LOGGER.info("Shutting down server...");
+ LOGGER.info("Stopping server...");
- Collections.reverse(services);
- for (LifecycleObject service : services) {
- if (service != null) {
- service.stop();
- }
+ for (var service : services) {
+ service.stop();
}
}));
} catch (Exception e) {