aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <atananaev@lyft.com>2020-12-29 11:22:01 -0800
committerAnton Tananaev <atananaev@lyft.com>2020-12-29 11:22:01 -0800
commitc0dee04079cb2edb855e6eeeab9cb6f1b43fa465 (patch)
tree4692f986852f2b7a557c47a332f40e5ce82d2058 /src
parent47468774b6b87c67d8ba98e52bfece04d6d48d1a (diff)
downloadtrackermap-server-c0dee04079cb2edb855e6eeeab9cb6f1b43fa465.tar.gz
trackermap-server-c0dee04079cb2edb855e6eeeab9cb6f1b43fa465.tar.bz2
trackermap-server-c0dee04079cb2edb855e6eeeab9cb6f1b43fa465.zip
Migrate keys and remove database cleanup
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/Main.java14
-rw-r--r--src/main/java/org/traccar/config/Keys.java24
-rw-r--r--src/main/java/org/traccar/database/DataManager.java21
-rw-r--r--src/main/java/org/traccar/web/WebServer.java2
4 files changed, 27 insertions, 34 deletions
diff --git a/src/main/java/org/traccar/Main.java b/src/main/java/org/traccar/Main.java
index 59afab3a5..993c68365 100644
--- a/src/main/java/org/traccar/Main.java
+++ b/src/main/java/org/traccar/Main.java
@@ -119,19 +119,6 @@ public final class Main {
}
}
- private static void scheduleDatabaseCleanup() {
- new Timer().scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- try {
- Context.getDataManager().clearHistory();
- } catch (SQLException error) {
- LOGGER.warn("Clear history error", error);
- }
- }
- }, 0, CLEAN_PERIOD);
- }
-
public static void run(String configFile) {
try {
Context.init(configFile);
@@ -147,7 +134,6 @@ public final class Main {
Context.getScheduleManager().start();
scheduleHealthCheck();
- scheduleDatabaseCleanup();
Thread.setDefaultUncaughtExceptionHandler((t, e) -> LOGGER.error("Thread exception", e));
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 4531c7541..f1efa7515 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -162,12 +162,27 @@ public final class Keys {
Collections.singletonList(KeyType.GLOBAL));
/**
+ * Automatically generate SQL database queries when possible.
+ */
+ public static final ConfigKey<Boolean> DATABASE_GENERATE_QUERIES = new ConfigKey<>(
+ "database.generateQueries",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
+ * Database connection pool size. Default value is defined by the HikariCP library.
+ */
+ public static final ConfigKey<Integer> DATABASE_MAX_POOL_SIZE = new ConfigKey<>(
+ "database.maxPoolSize",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
* SQL query to check connection status. Default value is 'SELECT 1'. For Oracle database you can use
* 'SELECT 1 FROM DUAL'.
*/
public static final ConfigKey<String> DATABASE_CHECK_CONNECTION = new ConfigKey<>(
"database.checkConnection",
- Collections.singletonList(KeyType.GLOBAL));
+ Collections.singletonList(KeyType.GLOBAL),
+ "SELECT 1");
/**
* Store original HEX or string data as "raw" attribute in the corresponding position.
@@ -321,6 +336,13 @@ public final class Keys {
60000L);
/**
+ * Authentication sessions timeout in seconds. By default no timeout.
+ */
+ public static final ConfigKey<Integer> WEB_SESSION_TIMEOUT = new ConfigKey<>(
+ "web.sessionTimeout",
+ Collections.singletonList(KeyType.GLOBAL));
+
+ /**
* Enable positions forwarding to other web server.
*/
public static final ConfigKey<Boolean> FORWARD_ENABLE = new ConfigKey<>(
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index d3a643c2e..4711c6ad2 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -114,16 +114,15 @@ public class DataManager {
hikariConfig.setJdbcUrl(config.getString(Keys.DATABASE_URL));
hikariConfig.setUsername(config.getString(Keys.DATABASE_USER));
hikariConfig.setPassword(config.getString(Keys.DATABASE_PASSWORD));
- hikariConfig.setConnectionInitSql(config.getString(Keys.DATABASE_CHECK_CONNECTION, "SELECT 1"));
+ hikariConfig.setConnectionInitSql(config.getString(Keys.DATABASE_CHECK_CONNECTION));
hikariConfig.setIdleTimeout(600000);
- int maxPoolSize = config.getInteger("database.maxPoolSize");
-
+ int maxPoolSize = config.getInteger(Keys.DATABASE_MAX_POOL_SIZE);
if (maxPoolSize != 0) {
hikariConfig.setMaximumPoolSize(maxPoolSize);
}
- generateQueries = config.getBoolean("database.generateQueries");
+ generateQueries = config.getBoolean(Keys.DATABASE_GENERATE_QUERIES);
dataSource = new HikariDataSource(hikariConfig);
}
@@ -342,20 +341,6 @@ public class DataManager {
.executeQuery(Position.class);
}
- public void clearHistory() throws SQLException {
- long historyDays = config.getInteger("database.historyDays");
- if (historyDays != 0) {
- Date timeLimit = new Date(System.currentTimeMillis() - historyDays * 24 * 3600 * 1000);
- LOGGER.info("Clearing history earlier than " + DateUtil.formatDate(timeLimit, false));
- QueryBuilder.create(dataSource, getQuery("database.deletePositions"))
- .setDate("serverTime", timeLimit)
- .executeUpdate();
- QueryBuilder.create(dataSource, getQuery("database.deleteEvents"))
- .setDate("serverTime", timeLimit)
- .executeUpdate();
- }
- }
-
public Server getServer() throws SQLException {
return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT_ALL, Server.class))
.executeQuerySingle(Server.class);
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java
index 1e9d716b4..4ae4d24ee 100644
--- a/src/main/java/org/traccar/web/WebServer.java
+++ b/src/main/java/org/traccar/web/WebServer.java
@@ -168,7 +168,7 @@ public class WebServer {
}
private void initSessionConfig(Config config, ServletContextHandler servletHandler) {
- int sessionTimeout = config.getInteger("web.sessionTimeout");
+ int sessionTimeout = config.getInteger(Keys.WEB_SESSION_TIMEOUT);
if (sessionTimeout > 0) {
servletHandler.getSessionHandler().setMaxInactiveInterval(sessionTimeout);
}