aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/Main.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-09 17:09:52 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-09 17:09:52 -0700
commit29b5d05cfd66a9f51b7ce272c1fb07077bc715b2 (patch)
treef9e4df6f47fd3723fe972893ca34273aa9979432 /src/main/java/org/traccar/Main.java
parent5b6bba55d960dcf4fc7721d1d2e75b950bb13809 (diff)
downloadtrackermap-server-29b5d05cfd66a9f51b7ce272c1fb07077bc715b2.tar.gz
trackermap-server-29b5d05cfd66a9f51b7ce272c1fb07077bc715b2.tar.bz2
trackermap-server-29b5d05cfd66a9f51b7ce272c1fb07077bc715b2.zip
Remove WebServer from context
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) {