aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/TimeHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-30 13:12:37 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-30 13:12:37 -0700
commitce661ec77a957b70c15509c6801e6f34b32ad11d (patch)
tree1fd501abc09e1eeceb3bf411b5d2612b27cc35ad /src/main/java/org/traccar/handler/TimeHandler.java
parent154ff3b2175e67b3fac531cb9c5c5c68880f5e12 (diff)
downloadtrackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.gz
trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.bz2
trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.zip
Improve dependency injection
Diffstat (limited to 'src/main/java/org/traccar/handler/TimeHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/TimeHandler.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/handler/TimeHandler.java b/src/main/java/org/traccar/handler/TimeHandler.java
index 822c22a0a..c7e5e6e5c 100644
--- a/src/main/java/org/traccar/handler/TimeHandler.java
+++ b/src/main/java/org/traccar/handler/TimeHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.model.Position;
+import javax.inject.Inject;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -31,11 +32,18 @@ import java.util.Set;
@ChannelHandler.Sharable
public class TimeHandler extends ChannelInboundHandlerAdapter {
+ private final boolean enabled;
private final boolean useServerTime;
private final Set<String> protocols;
+ @Inject
public TimeHandler(Config config) {
- useServerTime = config.getString(Keys.TIME_OVERRIDE).equalsIgnoreCase("serverTime");
+ enabled = config.hasKey(Keys.TIME_OVERRIDE);
+ if (enabled) {
+ useServerTime = config.getString(Keys.TIME_OVERRIDE).equalsIgnoreCase("serverTime");
+ } else {
+ useServerTime = false;
+ }
String protocolList = Context.getConfig().getString(Keys.TIME_PROTOCOLS);
if (protocolList != null) {
protocols = new HashSet<>(Arrays.asList(protocolList.split("[, ]")));
@@ -47,7 +55,7 @@ public class TimeHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
- if (msg instanceof Position && (protocols == null
+ if (enabled && msg instanceof Position && (protocols == null
|| protocols.contains(ctx.pipeline().get(BaseProtocolDecoder.class).getProtocolName()))) {
Position position = (Position) msg;