aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/handler
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 15:01:08 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 15:01:08 -0800
commite3668177e4cb989b596ed7b2eef71eb348860736 (patch)
tree7c5a0f131471ce8a3b5206a42fb44bb310d6ccf5 /src/org/traccar/handler
parent2af6e4cc6255f59acaa17e6763063b775d7ba1ea (diff)
downloadtraccar-server-e3668177e4cb989b596ed7b2eef71eb348860736.tar.gz
traccar-server-e3668177e4cb989b596ed7b2eef71eb348860736.tar.bz2
traccar-server-e3668177e4cb989b596ed7b2eef71eb348860736.zip
Refactor motion event handler
Diffstat (limited to 'src/org/traccar/handler')
-rw-r--r--src/org/traccar/handler/events/MotionEventHandler.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/org/traccar/handler/events/MotionEventHandler.java b/src/org/traccar/handler/events/MotionEventHandler.java
index 5e88d34b5..9ec02ccfb 100644
--- a/src/org/traccar/handler/events/MotionEventHandler.java
+++ b/src/org/traccar/handler/events/MotionEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,8 @@ import java.util.Collections;
import java.util.Map;
import io.netty.channel.ChannelHandler;
-import org.traccar.Context;
+import org.traccar.database.DeviceManager;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Device;
import org.traccar.model.DeviceState;
import org.traccar.model.Event;
@@ -31,9 +32,13 @@ import org.traccar.reports.model.TripsConfig;
@ChannelHandler.Sharable
public class MotionEventHandler extends BaseEventHandler {
- private TripsConfig tripsConfig;
+ private final IdentityManager identityManager;
+ private final DeviceManager deviceManager;
+ private final TripsConfig tripsConfig;
- public MotionEventHandler(TripsConfig tripsConfig) {
+ public MotionEventHandler(IdentityManager identityManager, DeviceManager deviceManager, TripsConfig tripsConfig) {
+ this.identityManager = identityManager;
+ this.deviceManager = deviceManager;
this.tripsConfig = tripsConfig;
}
@@ -106,24 +111,24 @@ public class MotionEventHandler extends BaseEventHandler {
protected Map<Event, Position> analyzePosition(Position position) {
long deviceId = position.getDeviceId();
- Device device = Context.getIdentityManager().getById(deviceId);
+ Device device = identityManager.getById(deviceId);
if (device == null) {
return null;
}
- if (!Context.getIdentityManager().isLatestPosition(position)
+ if (!identityManager.isLatestPosition(position)
|| !tripsConfig.getProcessInvalidPositions() && !position.getValid()) {
return null;
}
Map<Event, Position> result = null;
- DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
+ DeviceState deviceState = deviceManager.getDeviceState(deviceId);
if (deviceState.getMotionState() == null) {
deviceState.setMotionState(position.getBoolean(Position.KEY_MOTION));
} else {
result = updateMotionState(deviceState, position);
}
- Context.getDeviceManager().setDeviceState(deviceId, deviceState);
+ deviceManager.setDeviceState(deviceId, deviceState);
return result;
}