aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/Context.java11
-rw-r--r--src/main/java/org/traccar/MainModule.java9
-rw-r--r--src/main/java/org/traccar/database/NotificationManager.java20
3 files changed, 19 insertions, 21 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index 471416926..95ff2eddb 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -127,12 +127,6 @@ public final class Context {
return client;
}
- private static EventForwarder eventForwarder;
-
- public static EventForwarder getEventForwarder() {
- return eventForwarder;
- }
-
private static class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
@Override
@@ -181,10 +175,6 @@ public final class Context {
initEventsModule();
- if (config.hasKey(Keys.EVENT_FORWARD_URL)) {
- eventForwarder = new EventForwarder(config);
- }
-
}
private static void initEventsModule() {
@@ -192,6 +182,7 @@ public final class Context {
notificationManager = new NotificationManager(
dataManager,
Main.getInjector().getInstance(CacheManager.class),
+ Main.getInjector().getInstance(EventForwarder.class),
Main.getInjector().getInstance(NotificatorManager.class),
Main.getInjector().getInstance(Geocoder.class));
Properties velocityProperties = new Properties();
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index f6621a18e..e3f693444 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -25,6 +25,7 @@ import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.LdapProvider;
+import org.traccar.notification.EventForwarder;
import org.traccar.session.ConnectionManager;
import org.traccar.database.DataManager;
import org.traccar.database.DeviceManager;
@@ -269,4 +270,12 @@ public class MainModule extends AbstractModule {
return null;
}
+ @Provides
+ public static EventForwarder provideEventForwarder(Config config) {
+ if (config.hasKey(Keys.EVENT_FORWARD_URL)) {
+ return new EventForwarder(config);
+ }
+ return null;
+ }
+
}
diff --git a/src/main/java/org/traccar/database/NotificationManager.java b/src/main/java/org/traccar/database/NotificationManager.java
index 1f4a48ac0..3c87aacb2 100644
--- a/src/main/java/org/traccar/database/NotificationManager.java
+++ b/src/main/java/org/traccar/database/NotificationManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 - 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,6 +37,7 @@ import org.traccar.model.Notification;
import org.traccar.model.Position;
import org.traccar.model.Typed;
import org.traccar.model.User;
+import org.traccar.notification.EventForwarder;
import org.traccar.notification.MessageException;
import org.traccar.notification.NotificatorManager;
import org.traccar.session.cache.CacheManager;
@@ -49,16 +50,18 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
private static final Logger LOGGER = LoggerFactory.getLogger(NotificationManager.class);
private final CacheManager cacheManager;
+ private final EventForwarder eventForwarder;
private final NotificatorManager notificatorManager;
private final Geocoder geocoder;
private final boolean geocodeOnRequest;
public NotificationManager(
- DataManager dataManager, CacheManager cacheManager,
+ DataManager dataManager, CacheManager cacheManager, @Nullable EventForwarder eventForwarder,
NotificatorManager notificatorManager, @Nullable Geocoder geocoder) {
super(dataManager, Notification.class);
this.cacheManager = cacheManager;
+ this.eventForwarder = eventForwarder;
this.notificatorManager = notificatorManager;
this.geocoder = geocoder;
geocodeOnRequest = Context.getConfig().getBoolean(Keys.GEOCODER_ON_REQUEST);
@@ -88,14 +91,9 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
long deviceId = event.getDeviceId();
Set<Long> users = Context.getPermissionsManager().getDeviceUsers(deviceId);
- Set<Long> usersToForward = null;
- if (Context.getEventForwarder() != null) {
- usersToForward = new HashSet<>();
- }
+ Set<Long> usersToForward = new HashSet<>();
for (long userId : users) {
- if (usersToForward != null) {
- usersToForward.add(userId);
- }
+ usersToForward.add(userId);
final Set<String> notificators = new HashSet<>();
for (long notificationId : getEffectiveNotifications(userId, deviceId, event.getEventTime())) {
Notification notification = getById(notificationId);
@@ -131,8 +129,8 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
}
}).start();
}
- if (Context.getEventForwarder() != null) {
- Context.getEventForwarder().forwardEvent(event, position, usersToForward);
+ if (eventForwarder != null) {
+ eventForwarder.forwardEvent(event, position, usersToForward);
}
}