From ea22ffb859f8bb8fa0a468af192fef395653d645 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 4 Jun 2022 06:50:50 -0700 Subject: Remove more from context --- src/main/java/org/traccar/Context.java | 16 ---------------- src/main/java/org/traccar/Main.java | 5 +++-- src/main/java/org/traccar/ServerManager.java | 2 ++ .../java/org/traccar/api/resource/CommandResource.java | 7 +++++-- src/main/java/org/traccar/schedule/ScheduleManager.java | 2 ++ .../java/org/traccar/session/cache/CacheManager.java | 3 +-- 6 files changed, 13 insertions(+), 22 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java index 6ee8344ce..eaf973659 100644 --- a/src/main/java/org/traccar/Context.java +++ b/src/main/java/org/traccar/Context.java @@ -55,7 +55,6 @@ import org.traccar.model.User; import org.traccar.notification.EventForwarder; import org.traccar.notification.NotificatorManager; import org.traccar.reports.model.TripsConfig; -import org.traccar.schedule.ScheduleManager; import org.traccar.sms.HttpSmsClient; import org.traccar.sms.SmsManager; import org.traccar.sms.SnsSmsClient; @@ -149,18 +148,6 @@ public final class Context { return webServer; } - private static ServerManager serverManager; - - public static ServerManager getServerManager() { - return serverManager; - } - - private static ScheduleManager scheduleManager; - - public static ScheduleManager getScheduleManager() { - return scheduleManager; - } - private static BroadcastService broadcastService; public static BroadcastService getBroadcastService() { @@ -316,9 +303,6 @@ public final class Context { initEventsModule(); - serverManager = new ServerManager(); - scheduleManager = new ScheduleManager(); - if (config.hasKey(Keys.BROADCAST_ADDRESS)) { broadcastService = new BroadcastService(config, objectMapper); } diff --git a/src/main/java/org/traccar/Main.java b/src/main/java/org/traccar/Main.java index 016365837..db9892bb9 100644 --- a/src/main/java/org/traccar/Main.java +++ b/src/main/java/org/traccar/Main.java @@ -19,6 +19,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.traccar.schedule.ScheduleManager; import java.io.File; import java.lang.management.ManagementFactory; @@ -117,9 +118,9 @@ public final class Main { LOGGER.info("Starting server..."); List services = new LinkedList<>(); - services.add(Context.getServerManager()); + services.add(injector.getInstance(ServerManager.class)); services.add(Context.getWebServer()); - services.add(Context.getScheduleManager()); + services.add(injector.getInstance(ScheduleManager.class)); services.add(Context.getBroadcastService()); for (LifecycleObject service : services) { diff --git a/src/main/java/org/traccar/ServerManager.java b/src/main/java/org/traccar/ServerManager.java index 15faf9f2b..a6bb6888c 100644 --- a/src/main/java/org/traccar/ServerManager.java +++ b/src/main/java/org/traccar/ServerManager.java @@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory; import org.traccar.config.Keys; import org.traccar.helper.ClassScanner; +import javax.inject.Singleton; import java.io.IOException; import java.net.BindException; import java.net.ConnectException; @@ -29,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +@Singleton public class ServerManager implements LifecycleObject { private static final Logger LOGGER = LoggerFactory.getLogger(ServerManager.class); diff --git a/src/main/java/org/traccar/api/resource/CommandResource.java b/src/main/java/org/traccar/api/resource/CommandResource.java index 17bb150f6..60f1f8eb0 100644 --- a/src/main/java/org/traccar/api/resource/CommandResource.java +++ b/src/main/java/org/traccar/api/resource/CommandResource.java @@ -20,7 +20,7 @@ package org.traccar.api.resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.BaseProtocol; -import org.traccar.Context; +import org.traccar.ServerManager; import org.traccar.api.ExtendedObjectResource; import org.traccar.database.CommandsManager; import org.traccar.model.Command; @@ -60,6 +60,9 @@ public class CommandResource extends ExtendedObjectResource { @Inject private CommandsManager commandsManager; + @Inject + private ServerManager serverManager; + public CommandResource() { super(Command.class); } @@ -68,7 +71,7 @@ public class CommandResource extends ExtendedObjectResource { Position position = storage.getObject(Position.class, new Request( new Columns.All(), new Condition.LatestPositions(deviceId))); if (position != null) { - return Context.getServerManager().getProtocol(position.getProtocol()); + return serverManager.getProtocol(position.getProtocol()); } else { return null; } diff --git a/src/main/java/org/traccar/schedule/ScheduleManager.java b/src/main/java/org/traccar/schedule/ScheduleManager.java index 7a3d33b85..154de603a 100644 --- a/src/main/java/org/traccar/schedule/ScheduleManager.java +++ b/src/main/java/org/traccar/schedule/ScheduleManager.java @@ -17,9 +17,11 @@ package org.traccar.schedule; import org.traccar.LifecycleObject; +import javax.inject.Singleton; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +@Singleton public class ScheduleManager implements LifecycleObject { private ScheduledExecutorService executor; diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index 4669024d3..f2570f77c 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -50,8 +50,7 @@ import java.util.stream.Collectors; public class CacheManager { private static final Collection> CLASSES = Arrays.asList( - Attribute.class, Command.class, Driver.class, Geofence.class, - Maintenance.class, Notification.class, Order.class); + Attribute.class, Driver.class, Geofence.class, Maintenance.class, Notification.class); private final Storage storage; -- cgit v1.2.3