aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/ConnectionManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-08-11 23:37:16 +1200
committerGitHub <noreply@github.com>2017-08-11 23:37:16 +1200
commit30e8409375f9992a5248f7e2597691c0ee08188c (patch)
treeea51b7d111cfae849d23941ad82045139e87520b /src/org/traccar/database/ConnectionManager.java
parent3562e0d927d539a1e9730c48ed376ee84ebc2b25 (diff)
parent26db3ccc2ed5d43a0e791a29d5cc4afca192e4b7 (diff)
downloadtrackermap-server-30e8409375f9992a5248f7e2597691c0ee08188c.tar.gz
trackermap-server-30e8409375f9992a5248f7e2597691c0ee08188c.tar.bz2
trackermap-server-30e8409375f9992a5248f7e2597691c0ee08188c.zip
Merge pull request #3431 from Abyss777/delayed_overspeed
Implement delayed overspeed events
Diffstat (limited to 'src/org/traccar/database/ConnectionManager.java')
-rw-r--r--src/org/traccar/database/ConnectionManager.java52
1 files changed, 20 insertions, 32 deletions
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index 1c5d4428a..7a0a6d30d 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -21,13 +21,12 @@ import org.jboss.netty.util.TimerTask;
import org.traccar.Context;
import org.traccar.GlobalTimer;
import org.traccar.Protocol;
+import org.traccar.events.OverspeedEventHandler;
import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.DeviceState;
import org.traccar.model.Event;
import org.traccar.model.Position;
-import org.traccar.reports.ReportUtils;
-import org.traccar.reports.model.TripsConfig;
import java.net.SocketAddress;
import java.sql.SQLException;
@@ -44,7 +43,7 @@ public class ConnectionManager {
private final long deviceTimeout;
private final boolean enableStatusEvents;
- private TripsConfig tripsConfig = null;
+ private final boolean updateDeviceState;
private final Map<Long, ActiveDevice> activeDevices = new ConcurrentHashMap<>();
private final Map<Long, Set<UpdateListener>> listeners = new ConcurrentHashMap<>();
@@ -53,9 +52,7 @@ public class ConnectionManager {
public ConnectionManager() {
deviceTimeout = Context.getConfig().getLong("status.timeout", DEFAULT_TIMEOUT) * 1000;
enableStatusEvents = Context.getConfig().getBoolean("event.enable");
- if (Context.getConfig().getBoolean("status.updateDeviceState")) {
- tripsConfig = ReportUtils.initTripsConfig();
- }
+ updateDeviceState = Context.getConfig().getBoolean("status.updateDeviceState");
}
public void addActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
@@ -87,28 +84,24 @@ public class ConnectionManager {
if (enableStatusEvents && !status.equals(oldStatus)) {
String eventType;
- Event stateEvent = null;
+ Set<Event> events = new HashSet<>();
switch (status) {
case Device.STATUS_ONLINE:
eventType = Event.TYPE_DEVICE_ONLINE;
break;
case Device.STATUS_UNKNOWN:
eventType = Event.TYPE_DEVICE_UNKNOWN;
- if (tripsConfig != null) {
- stateEvent = updateDeviceState(deviceId);
+ if (updateDeviceState) {
+ events.addAll(updateDeviceState(deviceId));
}
break;
default:
eventType = Event.TYPE_DEVICE_OFFLINE;
- if (tripsConfig != null) {
- stateEvent = updateDeviceState(deviceId);
+ if (updateDeviceState) {
+ events.addAll(updateDeviceState(deviceId));
}
break;
}
- Set<Event> events = new HashSet<>();
- if (stateEvent != null) {
- events.add(stateEvent);
- }
events.add(new Event(eventType, deviceId));
Context.getNotificationManager().updateEvents(events, null);
}
@@ -142,26 +135,21 @@ public class ConnectionManager {
updateDevice(device);
}
- public Event updateDeviceState(long deviceId) {
+ public Set<Event> updateDeviceState(long deviceId) {
DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
- if (deviceState == null || deviceState.getMotionState() == null) {
- return null;
+ Set<Event> result = new HashSet<>();
+
+ Event event = Context.getMotionEventHandler().updateMotionState(deviceState);
+ if (event != null) {
+ result.add(event);
}
- Event result = null;
- Boolean oldMotion = deviceState.getMotionState();
- long currentTime = System.currentTimeMillis();
- boolean newMotion = !oldMotion;
- Position motionPosition = deviceState.getMotionPosition();
- if (motionPosition != null) {
- long motionTime = motionPosition.getFixTime().getTime()
- + (newMotion ? tripsConfig.getMinimalTripDuration() : tripsConfig.getMinimalParkingDuration());
- if (motionTime <= currentTime) {
- String eventType = newMotion ? Event.TYPE_DEVICE_MOVING : Event.TYPE_DEVICE_STOPPED;
- result = new Event(eventType, motionPosition.getDeviceId(), motionPosition.getId());
- deviceState.setMotionState(newMotion);
- deviceState.setMotionPosition(null);
- }
+
+ event = Context.getOverspeedEventHandler().updateOverspeedState(deviceState, Context.getDeviceManager().
+ lookupAttributeDouble(deviceId, OverspeedEventHandler.ATTRIBUTE_SPEED_LIMIT, 0, false));
+ if (event != null) {
+ result.add(event);
}
+
return result;
}