aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/ServerManager.java
diff options
context:
space:
mode:
authorYuriy Piskarev <yuriy.piskarev@gmail.com>2023-08-24 14:16:17 +0300
committerGitHub <noreply@github.com>2023-08-24 14:16:17 +0300
commitae406c7b49a72de24d81fd74386d9638342c90ee (patch)
tree6fbcf557375b98e926c78af9c757e62c79d72a1b /src/main/java/org/traccar/ServerManager.java
parent56ff656c908b19feb2fa3dcffa48cc3bcdfe9b3b (diff)
parent9aeedc90da24848ff97227d6f281eb4d1e1506ef (diff)
downloadtrackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.gz
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.tar.bz2
trackermap-server-ae406c7b49a72de24d81fd74386d9638342c90ee.zip
Merge branch 'traccar:master' into master
Diffstat (limited to 'src/main/java/org/traccar/ServerManager.java')
-rw-r--r--src/main/java/org/traccar/ServerManager.java38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/ServerManager.java b/src/main/java/org/traccar/ServerManager.java
index 15faf9f2b..e91be50a2 100644
--- a/src/main/java/org/traccar/ServerManager.java
+++ b/src/main/java/org/traccar/ServerManager.java
@@ -15,20 +15,28 @@
*/
package org.traccar;
+import com.google.inject.Injector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.helper.ClassScanner;
+import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
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
public class ServerManager implements LifecycleObject {
private static final Logger LOGGER = LoggerFactory.getLogger(ServerManager.class);
@@ -36,12 +44,21 @@ public class ServerManager implements LifecycleObject {
private final List<TrackerConnector> connectorList = new LinkedList<>();
private final Map<String, BaseProtocol> protocolList = new ConcurrentHashMap<>();
- public ServerManager() throws IOException, URISyntaxException, ReflectiveOperationException {
+ @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 (Context.getConfig().hasKey(Keys.PROTOCOL_PORT.withPrefix(BaseProtocol.nameFromClass(protocolClass)))) {
- BaseProtocol protocol = (BaseProtocol) protocolClass.getDeclaredConstructor().newInstance();
- 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);
+ }
}
}
}
@@ -64,11 +81,14 @@ public class ServerManager implements LifecycleObject {
}
@Override
- public void stop() {
- for (TrackerConnector connector: connectorList) {
- connector.stop();
+ public void stop() throws Exception {
+ try {
+ for (TrackerConnector connector : connectorList) {
+ connector.stop();
+ }
+ } finally {
+ GlobalTimer.release();
}
- GlobalTimer.release();
}
}