diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-16 20:47:59 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-16 20:47:59 -0700 |
commit | ee30e6e63f110476f557ed4ca8a081eb5b589101 (patch) | |
tree | e4a6deb28416b8aa613d5ecb383e6ebeecc79a6c /src/main | |
parent | ca4488bd093d25afa494ab30e117fdef98e20013 (diff) | |
download | trackermap-server-ee30e6e63f110476f557ed4ca8a081eb5b589101.tar.gz trackermap-server-ee30e6e63f110476f557ed4ca8a081eb5b589101.tar.bz2 trackermap-server-ee30e6e63f110476f557ed4ca8a081eb5b589101.zip |
Parameter to enable protocols (fix #3991)
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/ServerManager.java | 18 | ||||
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 10 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/ServerManager.java b/src/main/java/org/traccar/ServerManager.java index 8d6e615dc..57afb01fd 100644 --- a/src/main/java/org/traccar/ServerManager.java +++ b/src/main/java/org/traccar/ServerManager.java @@ -28,9 +28,12 @@ import java.io.IOException; import java.net.BindException; import java.net.ConnectException; import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @Singleton @@ -44,11 +47,18 @@ public class ServerManager implements LifecycleObject { @Inject public ServerManager( Injector injector, Config config) throws IOException, URISyntaxException, ReflectiveOperationException { + Set<String> enabledProtocols = null; + if (config.hasKey(Keys.PROTOCOLS_ENABLE)) { + enabledProtocols = new HashSet<>(Arrays.asList(config.getString(Keys.PROTOCOLS_ENABLE).split("[, ]"))); + } for (Class<?> protocolClass : ClassScanner.findSubclasses(BaseProtocol.class, "org.traccar.protocol")) { - if (config.hasKey(Keys.PROTOCOL_PORT.withPrefix(BaseProtocol.nameFromClass(protocolClass)))) { - BaseProtocol protocol = (BaseProtocol) injector.getInstance(protocolClass); - connectorList.addAll(protocol.getConnectorList()); - protocolList.put(protocol.getName(), protocol); + String protocolName = BaseProtocol.nameFromClass(protocolClass); + if (enabledProtocols == null || enabledProtocols.contains(protocolName)) { + if (config.hasKey(Keys.PROTOCOL_PORT.withPrefix(protocolName))) { + BaseProtocol protocol = (BaseProtocol) injector.getInstance(protocolClass); + connectorList.addAll(protocol.getConnectorList()); + protocolList.put(protocol.getName(), protocol); + } } } } diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 1217ab94c..2190f82f7 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1211,6 +1211,16 @@ public final class Keys { List.of(KeyType.CONFIG)); /** + * List of protocols to enable. If not specified, Traccar enabled all protocols that have port numbers listed. + * The value is a comma-separated list of protocol names. + * + * Example value: teltonika,osmand + */ + public static final ConfigKey<String> PROTOCOLS_ENABLE = new StringConfigKey( + "protocols.enable", + List.of(KeyType.CONFIG)); + + /** * List of protocols for overriding time. If not specified override is applied globally. List consist of protocol * names that can be separated by comma or single space character. */ |