From bdb4aea7ddb7f525d5c476077a88d905d261fdb8 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 29 Dec 2020 22:32:00 -0800 Subject: Migrate more keys --- src/main/java/org/traccar/Context.java | 6 ++-- src/main/java/org/traccar/MainModule.java | 2 +- src/main/java/org/traccar/config/Keys.java | 37 ++++++++++++++-------- .../org/traccar/database/ConnectionManager.java | 12 +++---- .../org/traccar/notification/EventForwarder.java | 5 +-- 5 files changed, 34 insertions(+), 28 deletions(-) (limited to 'src/main/java/org/traccar') 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 @@ -152,13 +152,6 @@ public final class Keys { "server.statistics", Collections.singletonList(KeyType.GLOBAL)); - /** - * Enable events subsystem. Flag to enable all events handlers. - */ - public static final ConfigKey EVENT_ENABLE = new ConfigKey<>( - "event.enable", - Collections.singletonList(KeyType.GLOBAL)); - /** * If true, the event is generated once at the beginning of overspeeding period. */ @@ -425,6 +418,13 @@ public final class Keys { Collections.singletonList(KeyType.GLOBAL), 600L); + /** + * Force additional state check when device status changes to 'offline' or 'unknown'. Default false. + */ + public static final ConfigKey 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. @@ -471,13 +471,6 @@ public final class Keys { "web.debug", Collections.singletonList(KeyType.GLOBAL)); - /** - * Enable positions forwarding to other web server. - */ - public static final ConfigKey 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. @@ -543,6 +536,22 @@ public final class Keys { "forward.retry.limit", Collections.singletonList(KeyType.GLOBAL)); + /** + * Events forwarding URL. + */ + public static final ConfigKey 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 EVENT_FORWARD_HEADERS = new ConfigKey<>( + "event.forward.header", + Collections.singletonList(KeyType.GLOBAL)); + /** * SMS API service full URL. Enables SMS commands and notifications. */ 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 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 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()); + 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()); + 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"; -- cgit v1.2.3