aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-09 07:08:39 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-09 07:08:39 -0700
commit4dbe47a2362bde8e2a8419b202a02e5e7fc16f87 (patch)
treefbc7dbdaa2316562f5aa4eeb0229f407a0d327af
parent12fe28bebbdbc61214363a9c7b51bd300ed62c15 (diff)
downloadtrackermap-server-4dbe47a2362bde8e2a8419b202a02e5e7fc16f87.tar.gz
trackermap-server-4dbe47a2362bde8e2a8419b202a02e5e7fc16f87.tar.bz2
trackermap-server-4dbe47a2362bde8e2a8419b202a02e5e7fc16f87.zip
Remove more from context
-rw-r--r--src/main/java/org/traccar/Context.java19
-rw-r--r--src/main/java/org/traccar/Main.java3
-rw-r--r--src/main/java/org/traccar/MainModule.java11
-rw-r--r--src/main/java/org/traccar/broadcast/BroadcastService.java2
4 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 dcbe6c811..1e158438f 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr353.JSR353Module;
import org.apache.velocity.app.VelocityEngine;
import org.eclipse.jetty.util.URIUtil;
-import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.BaseObjectManager;
@@ -132,12 +131,6 @@ public final class Context {
return webServer;
}
- private static BroadcastService broadcastService;
-
- public static BroadcastService getBroadcastService() {
- return broadcastService;
- }
-
private static NotificationManager notificationManager;
public static NotificationManager getNotificationManager() {
@@ -253,10 +246,6 @@ public final class Context {
initEventsModule();
- if (config.hasKey(Keys.BROADCAST_ADDRESS)) {
- broadcastService = new BroadcastService(config, objectMapper);
- }
-
if (config.hasKey(Keys.EVENT_FORWARD_URL)) {
eventForwarder = new EventForwarder(config);
}
@@ -288,14 +277,6 @@ public final class Context {
velocityEngine.init(velocityProperties);
}
- public static void init(IdentityManager testIdentityManager) {
- config = new Config();
- objectMapper = new ObjectMapper();
- objectMapper.registerModule(new JSR353Module());
- client = ClientBuilder.newClient().register(new ObjectMapperContextResolver());
- identityManager = testIdentityManager;
- }
-
public static <T extends BaseModel> BaseObjectManager<T> getManager(Class<T> clazz) {
if (clazz.equals(Device.class)) {
return (BaseObjectManager<T>) deviceManager;
diff --git a/src/main/java/org/traccar/Main.java b/src/main/java/org/traccar/Main.java
index b14f22a00..c35ea33a9 100644
--- a/src/main/java/org/traccar/Main.java
+++ b/src/main/java/org/traccar/Main.java
@@ -20,6 +20,7 @@ import com.google.inject.Injector;
import com.google.inject.servlet.ServletModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.traccar.broadcast.BroadcastService;
import org.traccar.schedule.ScheduleManager;
import java.io.File;
@@ -122,7 +123,7 @@ public final class Main {
services.add(injector.getInstance(ServerManager.class));
services.add(Context.getWebServer());
services.add(injector.getInstance(ScheduleManager.class));
- services.add(Context.getBroadcastService());
+ services.add(injector.getInstance(BroadcastService.class));
for (LifecycleObject service : services) {
if (service != null) {
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index bb264cff3..c9f2d4e62 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -21,6 +21,7 @@ import com.google.inject.Provides;
import com.google.inject.Scopes;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
+import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.LdapProvider;
@@ -65,6 +66,7 @@ import org.traccar.storage.Storage;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import javax.ws.rs.client.Client;
+import java.io.IOException;
public class MainModule extends AbstractModule {
@@ -247,4 +249,13 @@ public class MainModule extends AbstractModule {
return null;
}
+ @Provides
+ public static BroadcastService provideBroadcastService(
+ Config config, ObjectMapper objectMapper) throws IOException {
+ if (config.hasKey(Keys.BROADCAST_ADDRESS)) {
+ return new BroadcastService(config, objectMapper);
+ }
+ return null;
+ }
+
}
diff --git a/src/main/java/org/traccar/broadcast/BroadcastService.java b/src/main/java/org/traccar/broadcast/BroadcastService.java
index b17857fcd..26e38400b 100644
--- a/src/main/java/org/traccar/broadcast/BroadcastService.java
+++ b/src/main/java/org/traccar/broadcast/BroadcastService.java
@@ -22,7 +22,6 @@ import org.traccar.LifecycleObject;
import org.traccar.config.Config;
import org.traccar.config.Keys;
-import javax.inject.Inject;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
@@ -46,7 +45,6 @@ public class BroadcastService implements LifecycleObject {
private final ExecutorService service = Executors.newSingleThreadExecutor();
private final byte[] receiverBuffer = new byte[4096];
- @Inject
public BroadcastService(Config config, ObjectMapper objectMapper) throws IOException {
this.objectMapper = objectMapper;
address = InetAddress.getByName(config.getString(Keys.BROADCAST_ADDRESS));