diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-28 21:45:05 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-12-28 21:45:05 -0800 |
commit | 4f3d413a3003d7b9295c2e6801e7f3033738f65e (patch) | |
tree | 6b512462ec636b49e4001ab5017e8d1eb3f1535f /src/main/java | |
parent | 51704590a835057bf4850a5eaf8c5037d20f648a (diff) | |
download | traccar-server-4f3d413a3003d7b9295c2e6801e7f3033738f65e.tar.gz traccar-server-4f3d413a3003d7b9295c2e6801e7f3033738f65e.tar.bz2 traccar-server-4f3d413a3003d7b9295c2e6801e7f3033738f65e.zip |
Migrate more keys
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/traccar/ServerManager.java | 9 | ||||
-rw-r--r-- | src/main/java/org/traccar/TrackerServer.java | 5 | ||||
-rw-r--r-- | src/main/java/org/traccar/config/Config.java | 12 | ||||
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 32 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/WebServer.java | 6 |
5 files changed, 54 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/ServerManager.java b/src/main/java/org/traccar/ServerManager.java index 68b133c98..935a821aa 100644 --- a/src/main/java/org/traccar/ServerManager.java +++ b/src/main/java/org/traccar/ServerManager.java @@ -17,6 +17,7 @@ package org.traccar; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.traccar.config.Keys; import java.io.File; import java.io.IOException; @@ -70,10 +71,10 @@ public class ServerManager { } for (String name : names) { - Class protocolClass = Class.forName(packageName + '.' + name); - if (BaseProtocol.class.isAssignableFrom(protocolClass) - && Context.getConfig().hasKey(BaseProtocol.nameFromClass(protocolClass) + ".port")) { - BaseProtocol protocol = (BaseProtocol) protocolClass.newInstance(); + Class<?> protocolClass = Class.forName(packageName + '.' + name); + if (BaseProtocol.class.isAssignableFrom(protocolClass) && Context.getConfig().hasKey( + Keys.PROTOCOL_PORT.withPrefix(BaseProtocol.nameFromClass(protocolClass)))) { + BaseProtocol protocol = (BaseProtocol) protocolClass.getDeclaredConstructor().newInstance(); serverList.addAll(protocol.getServerList()); protocolList.put(protocol.getName(), protocol); } diff --git a/src/main/java/org/traccar/TrackerServer.java b/src/main/java/org/traccar/TrackerServer.java index 3a1e1c4e8..59ba123e2 100644 --- a/src/main/java/org/traccar/TrackerServer.java +++ b/src/main/java/org/traccar/TrackerServer.java @@ -24,6 +24,7 @@ import io.netty.channel.group.DefaultChannelGroup; import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.util.concurrent.GlobalEventExecutor; +import org.traccar.config.Keys; import java.net.InetSocketAddress; @@ -39,8 +40,8 @@ public abstract class TrackerServer { public TrackerServer(boolean datagram, String protocol) { this.datagram = datagram; - address = Context.getConfig().getString(protocol + ".address"); - port = Context.getConfig().getInteger(protocol + ".port"); + address = Context.getConfig().getString(Keys.PROTOCOL_ADDRESS.withPrefix(protocol)); + port = Context.getConfig().getInteger(Keys.PROTOCOL_PORT.withPrefix(protocol)); BasePipelineFactory pipelineFactory = new BasePipelineFactory(this, protocol) { @Override diff --git a/src/main/java/org/traccar/config/Config.java b/src/main/java/org/traccar/config/Config.java index 713f5c607..dd61e1f00 100644 --- a/src/main/java/org/traccar/config/Config.java +++ b/src/main/java/org/traccar/config/Config.java @@ -99,7 +99,17 @@ public class Config { } public int getInteger(ConfigKey<Integer> key) { - return getInteger(key.getKey()); + String value = getString(key.getKey()); + if (value != null) { + return Integer.parseInt(value); + } else { + Integer defaultValue = key.getDefaultValue(); + if (defaultValue != null) { + return defaultValue; + } else { + return 0; + } + } } @Deprecated diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index ea3176afd..215b00805 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -20,6 +20,21 @@ import java.util.Collections; public final class Keys { /** + * Network interface for a the protocol. If not specified, server will bind all interfaces. + */ + public static final ConfigSuffix<String> PROTOCOL_ADDRESS = new ConfigSuffix<>( + ".address", + Collections.singletonList(KeyType.GLOBAL)); + + /** + * Port number for the protocol. Most protocols use TCP on the transport layer. Some protocols use UDP. Some + * support both TCP and UDP. + */ + public static final ConfigSuffix<Integer> PROTOCOL_PORT = new ConfigSuffix<>( + ".port", + Collections.singletonList(KeyType.GLOBAL)); + + /** * Connection timeout value in seconds. Because sometimes there is no way to detect lost TCP connection old * connections stay in open state. On most systems there is a limit on number of open connection, so this leads to * problems with establishing new connections when number of devices is high or devices data connections are @@ -193,6 +208,23 @@ public final class Keys { 600L); /** + * Optional parameter to specify network interface for web interface to bind to. By default server will bind to all + * available interfaces. + */ + public static final ConfigKey<String> WEB_ADDRESS = new ConfigKey<>( + "web.address", + Collections.singletonList(KeyType.GLOBAL)); + + /** + * Web interface TCP port number. By default Traccar uses port 8082. To avoid specifying port in the browser you + * can set it to 80 (default HTTP port). + */ + public static final ConfigKey<Integer> WEB_PORT = new ConfigKey<>( + "web.port", + Collections.singletonList(KeyType.GLOBAL), + 8082); + + /** * WebSocket connection timeout in milliseconds. Default timeout is 10 minutes. */ public static final ConfigKey<Long> WEB_TIMEOUT = new ConfigKey<>( diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java index 28fa45273..1e9d716b4 100644 --- a/src/main/java/org/traccar/web/WebServer.java +++ b/src/main/java/org/traccar/web/WebServer.java @@ -64,8 +64,8 @@ public class WebServer { private void initServer(Config config) { - String address = config.getString("web.address"); - int port = config.getInteger("web.port", 8082); + String address = config.getString(Keys.WEB_ADDRESS); + int port = config.getInteger(Keys.WEB_PORT); if (address == null) { server = new Server(port); } else { @@ -113,7 +113,7 @@ public class WebServer { } private void initClientProxy(Config config, HandlerList handlers) { - int port = config.getInteger("osmand.port"); + int port = config.getInteger(Keys.PROTOCOL_PORT.withPrefix("osmand")); if (port != 0) { ServletContextHandler servletHandler = new ServletContextHandler() { @Override |