aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-12-29 22:32:00 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2020-12-29 22:32:00 -0800
commitbdb4aea7ddb7f525d5c476077a88d905d261fdb8 (patch)
treecfa8352aab61762644ece9f01b7997c05b4a19a4 /src/main/java/org
parent8fe1e679935688676f7139bb9ed6dc61838d0e2f (diff)
downloadtrackermap-server-bdb4aea7ddb7f525d5c476077a88d905d261fdb8.tar.gz
trackermap-server-bdb4aea7ddb7f525d5c476077a88d905d261fdb8.tar.bz2
trackermap-server-bdb4aea7ddb7f525d5c476077a88d905d261fdb8.zip
Migrate more keys
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/Context.java6
-rw-r--r--src/main/java/org/traccar/MainModule.java2
-rw-r--r--src/main/java/org/traccar/config/Keys.java37
-rw-r--r--src/main/java/org/traccar/database/ConnectionManager.java12
-rw-r--r--src/main/java/org/traccar/notification/EventForwarder.java5
5 files changed, 34 insertions, 28 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index 9a382adb4..a870edb4b 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -319,14 +319,12 @@ public final class Context {
smsManager = new HttpSmsClient();
}
- if (config.getBoolean("event.enable")) {
- initEventsModule();
- }
+ initEventsModule();
serverManager = new ServerManager();
scheduleManager = new ScheduleManager();
- if (config.getBoolean("event.forward.enable")) {
+ if (config.hasKey(Keys.EVENT_FORWARD_URL)) {
eventForwarder = new EventForwarder();
}
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index e751cb453..77f0c89d1 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -264,7 +264,7 @@ public class MainModule extends AbstractModule {
@Provides
public static WebDataHandler provideWebDataHandler(
Config config, IdentityManager identityManager, ObjectMapper objectMapper, Client client) {
- if (config.getBoolean(Keys.FORWARD_ENABLE)) {
+ if (config.hasKey(Keys.FORWARD_URL)) {
return new WebDataHandler(config, identityManager, objectMapper, client);
}
return null;
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 96ed7773b..da6c46ee9 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -153,13 +153,6 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
- * Enable events subsystem. Flag to enable all events handlers.
- */
- public static final ConfigKey<Boolean> EVENT_ENABLE = new ConfigKey<>(
- "event.enable",
- Collections.singletonList(KeyType.GLOBAL));
-
- /**
* If true, the event is generated once at the beginning of overspeeding period.
*/
public static final ConfigKey<Boolean> EVENT_OVERSPEED_NOT_REPEAT = new ConfigKey<>(
@@ -426,6 +419,13 @@ public final class Keys {
600L);
/**
+ * Force additional state check when device status changes to 'offline' or 'unknown'. Default false.
+ */
+ public static final ConfigKey<Boolean> STATUS_UPDATE_DEVICE_STATE = new ConfigKey<>(
+ "status.updateDeviceState",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
* Optional parameter to specify network interface for web interface to bind to. By default server will bind to all
* available interfaces.
*/
@@ -472,13 +472,6 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
- * Enable positions forwarding to other web server.
- */
- public static final ConfigKey<Boolean> FORWARD_ENABLE = new ConfigKey<>(
- "forward.enable",
- Collections.singletonList(KeyType.GLOBAL));
-
- /**
* URL to forward positions. Data is passed through URL parameters. For example, {uniqueId} for device identifier,
* {latitude} and {longitude} for coordinates.
*/
@@ -544,6 +537,22 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
+ * Events forwarding URL.
+ */
+ public static final ConfigKey<String> EVENT_FORWARD_URL = new ConfigKey<>(
+ "event.forward.url",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Events forwarding headers. Example value:
+ * FirstHeader: hello
+ * SecondHeader: world
+ */
+ public static final ConfigKey<String> EVENT_FORWARD_HEADERS = new ConfigKey<>(
+ "event.forward.header",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
* SMS API service full URL. Enables SMS commands and notifications.
*/
public static final ConfigKey<String> SMS_HTTP_URL = new ConfigKey<>(
diff --git a/src/main/java/org/traccar/database/ConnectionManager.java b/src/main/java/org/traccar/database/ConnectionManager.java
index 8278baa7c..5ff27c187 100644
--- a/src/main/java/org/traccar/database/ConnectionManager.java
+++ b/src/main/java/org/traccar/database/ConnectionManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,6 @@ public class ConnectionManager {
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionManager.class);
private final long deviceTimeout;
- private final boolean enableStatusEvents;
private final boolean updateDeviceState;
private final Map<Long, ActiveDevice> activeDevices = new ConcurrentHashMap<>();
@@ -55,8 +54,7 @@ public class ConnectionManager {
public ConnectionManager() {
deviceTimeout = Context.getConfig().getLong(Keys.STATUS_TIMEOUT) * 1000;
- enableStatusEvents = Context.getConfig().getBoolean("event.enable");
- updateDeviceState = Context.getConfig().getBoolean("status.updateDeviceState");
+ updateDeviceState = Context.getConfig().getBoolean(Keys.STATUS_UPDATE_DEVICE_STATE);
}
public void addActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
@@ -86,7 +84,7 @@ public class ConnectionManager {
String oldStatus = device.getStatus();
device.setStatus(status);
- if (enableStatusEvents && !status.equals(oldStatus)) {
+ if (!status.equals(oldStatus)) {
String eventType;
Map<Event, Position> events = new HashMap<>();
switch (status) {
@@ -194,14 +192,14 @@ public class ConnectionManager {
public synchronized void addListener(long userId, UpdateListener listener) {
if (!listeners.containsKey(userId)) {
- listeners.put(userId, new HashSet<UpdateListener>());
+ listeners.put(userId, new HashSet<>());
}
listeners.get(userId).add(listener);
}
public synchronized void removeListener(long userId, UpdateListener listener) {
if (!listeners.containsKey(userId)) {
- listeners.put(userId, new HashSet<UpdateListener>());
+ listeners.put(userId, new HashSet<>());
}
listeners.get(userId).remove(listener);
}
diff --git a/src/main/java/org/traccar/notification/EventForwarder.java b/src/main/java/org/traccar/notification/EventForwarder.java
index 966bff31d..c908fedbd 100644
--- a/src/main/java/org/traccar/notification/EventForwarder.java
+++ b/src/main/java/org/traccar/notification/EventForwarder.java
@@ -18,6 +18,7 @@ package org.traccar.notification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
+import org.traccar.config.Keys;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
@@ -39,8 +40,8 @@ public class EventForwarder {
private final String header;
public EventForwarder() {
- url = Context.getConfig().getString("event.forward.url", "http://localhost/");
- header = Context.getConfig().getString("event.forward.header");
+ url = Context.getConfig().getString(Keys.EVENT_FORWARD_URL);
+ header = Context.getConfig().getString(Keys.EVENT_FORWARD_HEADERS);
}
private static final String KEY_POSITION = "position";