diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-27 14:39:34 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-27 14:39:34 +1300 |
commit | dcf55c4f291c441b5e9921ec5b25ec8d3414140d (patch) | |
tree | 49997e43f6524162a95065d8fb405ed5f2b30c1f | |
parent | 67f512fb2b481ebca78dab2163733ca2c3cef55a (diff) | |
download | trackermap-server-dcf55c4f291c441b5e9921ec5b25ec8d3414140d.tar.gz trackermap-server-dcf55c4f291c441b5e9921ec5b25ec8d3414140d.tar.bz2 trackermap-server-dcf55c4f291c441b5e9921ec5b25ec8d3414140d.zip |
Option to enable H2 database console
-rw-r--r-- | debug.xml | 3 | ||||
-rw-r--r-- | src/org/traccar/Context.java | 24 | ||||
-rw-r--r-- | src/org/traccar/Main.java | 10 |
3 files changed, 35 insertions, 2 deletions
@@ -25,6 +25,9 @@ <entry key='distance.enable'>true</entry> + <entry key='console.enable'>true</entry> + <entry key='console.port'>8083</entry> + <!--<entry key='filter.enable'>true</entry> <entry key='filter.limit'>3600</entry> <entry key='filter.invalid'>true</entry> diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index c833d0c2e..675465aff 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -16,6 +16,8 @@ package org.traccar; import com.ning.http.client.AsyncHttpClient; +import org.h2.server.web.ConnectionInfo; +import org.h2.tools.Server; import org.traccar.database.ConnectionManager; import org.traccar.database.DataManager; import org.traccar.database.IdentityManager; @@ -34,6 +36,8 @@ import org.traccar.location.MozillaLocationProvider; import org.traccar.location.OpenCellIdLocationProvider; import org.traccar.web.WebServer; +import java.lang.reflect.Method; + public final class Context { private Context() { @@ -93,6 +97,12 @@ public final class Context { return webServer; } + private static Server databaseConsole; + + public static Server getDatabaseConsole() { + return databaseConsole; + } + private static ServerManager serverManager; public static ServerManager getServerManager() { @@ -175,6 +185,20 @@ public final class Context { webServer = new WebServer(config, dataManager.getDataSource()); } + if (config.getBoolean("console.enable")) { + databaseConsole = Server.createWebServer("-webPort", config.getString("console.port")); + org.h2.server.web.WebServer databaseService = (org.h2.server.web.WebServer) databaseConsole.getService(); + + ConnectionInfo connectionInfo = new ConnectionInfo("Traccar|" + + config.getString("database.driver") + "|" + + config.getString("database.url") + "|" + + config.getString("database.user")); + + Method method = databaseService.getClass().getDeclaredMethod("updateSetting", ConnectionInfo.class); + method.setAccessible(true); + method.invoke(databaseService, connectionInfo); + } + connectionManager = new ConnectionManager(dataManager); serverManager = new ServerManager(); diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java index a51fa80bf..7c2e00ca0 100644 --- a/src/org/traccar/Main.java +++ b/src/org/traccar/Main.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,12 +33,18 @@ public final class Main { if (Context.getWebServer() != null) { Context.getWebServer().start(); } + if (Context.getDatabaseConsole() != null) { + Context.getDatabaseConsole().start(); + } - // Shutdown server properly Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { Log.info("Shutting down server..."); + + if (Context.getDatabaseConsole() != null) { + Context.getDatabaseConsole().stop(); + } if (Context.getWebServer() != null) { Context.getWebServer().stop(); } |