aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-04 06:50:50 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-04 06:50:50 -0700
commitea22ffb859f8bb8fa0a468af192fef395653d645 (patch)
tree959ceef93b645ae1573de1cf0eba86b657dec92c /src
parentec76482c15094a7e04964c67d3011a7e8e1ad6a9 (diff)
downloadtrackermap-server-ea22ffb859f8bb8fa0a468af192fef395653d645.tar.gz
trackermap-server-ea22ffb859f8bb8fa0a468af192fef395653d645.tar.bz2
trackermap-server-ea22ffb859f8bb8fa0a468af192fef395653d645.zip
Remove more from context
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/Context.java16
-rw-r--r--src/main/java/org/traccar/Main.java5
-rw-r--r--src/main/java/org/traccar/ServerManager.java2
-rw-r--r--src/main/java/org/traccar/api/resource/CommandResource.java7
-rw-r--r--src/main/java/org/traccar/schedule/ScheduleManager.java2
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java3
6 files changed, 13 insertions, 22 deletions
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<LifecycleObject> 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<Command> {
@Inject
private CommandsManager commandsManager;
+ @Inject
+ private ServerManager serverManager;
+
public CommandResource() {
super(Command.class);
}
@@ -68,7 +71,7 @@ public class CommandResource extends ExtendedObjectResource<Command> {
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<Class<? extends BaseModel>> 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;