aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/BaseEventHandler.java8
-rw-r--r--src/org/traccar/database/ConnectionManager.java21
-rw-r--r--src/org/traccar/database/NotificationManager.java7
-rw-r--r--src/org/traccar/events/AlertEventHandler.java6
-rw-r--r--src/org/traccar/events/CommandResultEventHandler.java6
-rw-r--r--src/org/traccar/events/DriverEventHandler.java6
-rw-r--r--src/org/traccar/events/FuelDropEventHandler.java6
-rw-r--r--src/org/traccar/events/GeofenceEventHandler.java11
-rw-r--r--src/org/traccar/events/IgnitionEventHandler.java14
-rw-r--r--src/org/traccar/events/MaintenanceEventHandler.java6
-rw-r--r--src/org/traccar/events/MotionEventHandler.java29
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java27
-rw-r--r--src/org/traccar/reports/ReportUtils.java9
13 files changed, 76 insertions, 80 deletions
diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java
index 588406bf4..b6f7e2085 100644
--- a/src/org/traccar/BaseEventHandler.java
+++ b/src/org/traccar/BaseEventHandler.java
@@ -15,7 +15,7 @@
*/
package org.traccar;
-import java.util.Collection;
+import java.util.Map;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -25,13 +25,13 @@ public abstract class BaseEventHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
- Collection<Event> events = analyzePosition(position);
+ Map<Event, Position> events = analyzePosition(position);
if (events != null && Context.getNotificationManager() != null) {
- Context.getNotificationManager().updateEvents(events, position);
+ Context.getNotificationManager().updateEvents(events);
}
return position;
}
- protected abstract Collection<Event> analyzePosition(Position position);
+ protected abstract Map<Event, Position> analyzePosition(Position position);
}
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index 7a0a6d30d..de11db21b 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -31,6 +31,7 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.sql.SQLException;
import java.util.Date;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -84,7 +85,7 @@ public class ConnectionManager {
if (enableStatusEvents && !status.equals(oldStatus)) {
String eventType;
- Set<Event> events = new HashSet<>();
+ Map<Event, Position> events = new HashMap<>();
switch (status) {
case Device.STATUS_ONLINE:
eventType = Event.TYPE_DEVICE_ONLINE;
@@ -92,18 +93,18 @@ public class ConnectionManager {
case Device.STATUS_UNKNOWN:
eventType = Event.TYPE_DEVICE_UNKNOWN;
if (updateDeviceState) {
- events.addAll(updateDeviceState(deviceId));
+ events.putAll(updateDeviceState(deviceId));
}
break;
default:
eventType = Event.TYPE_DEVICE_OFFLINE;
if (updateDeviceState) {
- events.addAll(updateDeviceState(deviceId));
+ events.putAll(updateDeviceState(deviceId));
}
break;
}
- events.add(new Event(eventType, deviceId));
- Context.getNotificationManager().updateEvents(events, null);
+ events.put(new Event(eventType, deviceId), null);
+ Context.getNotificationManager().updateEvents(events);
}
Timeout timeout = timeouts.remove(deviceId);
@@ -135,19 +136,19 @@ public class ConnectionManager {
updateDevice(device);
}
- public Set<Event> updateDeviceState(long deviceId) {
+ public Map<Event, Position> updateDeviceState(long deviceId) {
DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
- Set<Event> result = new HashSet<>();
+ Map<Event, Position> result = new HashMap<>();
- Event event = Context.getMotionEventHandler().updateMotionState(deviceState);
+ Map<Event, Position> event = Context.getMotionEventHandler().updateMotionState(deviceState);
if (event != null) {
- result.add(event);
+ result.putAll(event);
}
event = Context.getOverspeedEventHandler().updateOverspeedState(deviceState, Context.getDeviceManager().
lookupAttributeDouble(deviceId, OverspeedEventHandler.ATTRIBUTE_SPEED_LIMIT, 0, false));
if (event != null) {
- result.add(event);
+ result.putAll(event);
}
return result;
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
index 0987f255b..98cae3499 100644
--- a/src/org/traccar/database/NotificationManager.java
+++ b/src/org/traccar/database/NotificationManager.java
@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -77,9 +78,9 @@ public class NotificationManager {
}
}
- public void updateEvents(Collection<Event> events, Position position) {
- for (Event event : events) {
- updateEvent(event, position);
+ public void updateEvents(Map<Event, Position> events) {
+ for (Entry<Event, Position> event : events.entrySet()) {
+ updateEvent(event.getKey(), event.getValue());
}
}
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java
index 7d0bd669b..003ccb662 100644
--- a/src/org/traccar/events/AlertEventHandler.java
+++ b/src/org/traccar/events/AlertEventHandler.java
@@ -15,8 +15,8 @@
*/
package org.traccar.events;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.model.Event;
@@ -25,12 +25,12 @@ import org.traccar.model.Position;
public class AlertEventHandler extends BaseEventHandler {
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
Object alarm = position.getAttributes().get(Position.KEY_ALARM);
if (alarm != null) {
Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId());
event.set(Position.KEY_ALARM, (String) alarm);
- return Collections.singleton(event);
+ return Collections.singletonMap(event, position);
}
return null;
}
diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java
index 077c389c9..775aa903f 100644
--- a/src/org/traccar/events/CommandResultEventHandler.java
+++ b/src/org/traccar/events/CommandResultEventHandler.java
@@ -15,8 +15,8 @@
*/
package org.traccar.events;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.model.Event;
@@ -25,12 +25,12 @@ import org.traccar.model.Position;
public class CommandResultEventHandler extends BaseEventHandler {
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
Object commandResult = position.getAttributes().get(Position.KEY_RESULT);
if (commandResult != null) {
Event event = new Event(Event.TYPE_COMMAND_RESULT, position.getDeviceId(), position.getId());
event.set(Position.KEY_RESULT, (String) commandResult);
- return Collections.singleton(event);
+ return Collections.singletonMap(event, position);
}
return null;
}
diff --git a/src/org/traccar/events/DriverEventHandler.java b/src/org/traccar/events/DriverEventHandler.java
index eb5f2a301..39b8eb9c0 100644
--- a/src/org/traccar/events/DriverEventHandler.java
+++ b/src/org/traccar/events/DriverEventHandler.java
@@ -16,8 +16,8 @@
*/
package org.traccar.events;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -27,7 +27,7 @@ import org.traccar.model.Position;
public class DriverEventHandler extends BaseEventHandler {
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
if (!Context.getIdentityManager().isLatestPosition(position)) {
return null;
}
@@ -41,7 +41,7 @@ public class DriverEventHandler extends BaseEventHandler {
if (!driverUniqueId.equals(oldDriverUniqueId)) {
Event event = new Event(Event.TYPE_DRIVER_CHANGED, position.getDeviceId(), position.getId());
event.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId);
- return Collections.singleton(event);
+ return Collections.singletonMap(event, position);
}
}
return null;
diff --git a/src/org/traccar/events/FuelDropEventHandler.java b/src/org/traccar/events/FuelDropEventHandler.java
index 4e09bd4fa..4fc512162 100644
--- a/src/org/traccar/events/FuelDropEventHandler.java
+++ b/src/org/traccar/events/FuelDropEventHandler.java
@@ -21,15 +21,15 @@ import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
public class FuelDropEventHandler extends BaseEventHandler {
public static final String ATTRIBUTE_FUEL_DROP_THRESHOLD = "fuelDropThreshold";
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null) {
@@ -52,7 +52,7 @@ public class FuelDropEventHandler extends BaseEventHandler {
if (drop >= fuelDropThreshold) {
Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position.getDeviceId(), position.getId());
event.set(ATTRIBUTE_FUEL_DROP_THRESHOLD, fuelDropThreshold);
- return Collections.singleton(event);
+ return Collections.singletonMap(event, position);
}
}
}
diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java
index 79e5d0f8e..31d82a81e 100644
--- a/src/org/traccar/events/GeofenceEventHandler.java
+++ b/src/org/traccar/events/GeofenceEventHandler.java
@@ -16,8 +16,9 @@
package org.traccar.events;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -36,7 +37,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
}
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null) {
return null;
@@ -56,14 +57,14 @@ public class GeofenceEventHandler extends BaseEventHandler {
device.setGeofenceIds(currentGeofences);
- Collection<Event> events = new ArrayList<>();
+ Map<Event, Position> events = new HashMap<>();
for (long geofenceId : newGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
- events.add(event);
+ events.put(event, position);
}
}
for (long geofenceId : oldGeofences) {
@@ -72,7 +73,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
- events.add(event);
+ events.put(event, position);
}
}
return events;
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java
index 5519135bf..cc53b216c 100644
--- a/src/org/traccar/events/IgnitionEventHandler.java
+++ b/src/org/traccar/events/IgnitionEventHandler.java
@@ -16,8 +16,8 @@
*/
package org.traccar.events;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -28,13 +28,13 @@ import org.traccar.model.Position;
public class IgnitionEventHandler extends BaseEventHandler {
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
return null;
}
- Collection<Event> result = null;
+ Map<Event, Position> result = null;
if (position.getAttributes().containsKey(Position.KEY_IGNITION)) {
boolean ignition = position.getBoolean(Position.KEY_IGNITION);
@@ -44,11 +44,11 @@ public class IgnitionEventHandler extends BaseEventHandler {
boolean oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION);
if (ignition && !oldIgnition) {
- result = Collections.singleton(
- new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()));
+ result = Collections.singletonMap(
+ new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()), position);
} else if (!ignition && oldIgnition) {
- result = Collections.singleton(
- new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()));
+ result = Collections.singletonMap(
+ new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()), position);
}
}
}
diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java
index ffeefc8c5..86abf7c17 100644
--- a/src/org/traccar/events/MaintenanceEventHandler.java
+++ b/src/org/traccar/events/MaintenanceEventHandler.java
@@ -16,8 +16,8 @@
*/
package org.traccar.events;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -31,7 +31,7 @@ public class MaintenanceEventHandler extends BaseEventHandler {
public static final String ATTRIBUTE_MAINTENANCE_INTERVAL = "maintenance.interval";
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
return null;
@@ -60,7 +60,7 @@ public class MaintenanceEventHandler extends BaseEventHandler {
if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) {
Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance);
- return Collections.singleton(event);
+ return Collections.singletonMap(event, position);
}
return null;
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index b96898fc1..ae64c10ea 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -16,8 +16,8 @@
*/
package org.traccar.events;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -36,17 +36,17 @@ public class MotionEventHandler extends BaseEventHandler {
this.tripsConfig = tripsConfig;
}
- private Event newEvent(DeviceState deviceState, boolean newMotion) {
+ private Map<Event, Position> newEvent(DeviceState deviceState, boolean newMotion) {
String eventType = newMotion ? Event.TYPE_DEVICE_MOVING : Event.TYPE_DEVICE_STOPPED;
- Event event = new Event(eventType, deviceState.getMotionPosition().getDeviceId(),
- deviceState.getMotionPosition().getId());
+ Position position = deviceState.getMotionPosition();
+ Event event = new Event(eventType, position.getDeviceId(), position.getId());
deviceState.setMotionState(newMotion);
deviceState.setMotionPosition(null);
- return event;
+ return Collections.singletonMap(event, position);
}
- public Event updateMotionState(DeviceState deviceState) {
- Event result = null;
+ public Map<Event, Position> updateMotionState(DeviceState deviceState) {
+ Map<Event, Position> result = null;
if (deviceState.getMotionState() != null && deviceState.getMotionPosition() != null) {
boolean newMotion = !deviceState.getMotionState();
Position motionPosition = deviceState.getMotionPosition();
@@ -60,12 +60,12 @@ public class MotionEventHandler extends BaseEventHandler {
return result;
}
- public Event updateMotionState(DeviceState deviceState, Position position) {
+ public Map<Event, Position> updateMotionState(DeviceState deviceState, Position position) {
return updateMotionState(deviceState, position, position.getBoolean(Position.KEY_MOTION));
}
- public Event updateMotionState(DeviceState deviceState, Position position, boolean newMotion) {
- Event result = null;
+ public Map<Event, Position> updateMotionState(DeviceState deviceState, Position position, boolean newMotion) {
+ Map<Event, Position> result = null;
Boolean oldMotion = deviceState.getMotionState();
long currentTime = position.getFixTime().getTime();
@@ -102,7 +102,7 @@ public class MotionEventHandler extends BaseEventHandler {
}
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
long deviceId = position.getDeviceId();
Device device = Context.getIdentityManager().getById(deviceId);
@@ -113,7 +113,7 @@ public class MotionEventHandler extends BaseEventHandler {
return null;
}
- Event result = null;
+ Map<Event, Position> result = null;
DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
if (deviceState.getMotionState() == null) {
@@ -122,10 +122,7 @@ public class MotionEventHandler extends BaseEventHandler {
result = updateMotionState(deviceState, position);
}
Context.getDeviceManager().setDeviceState(deviceId, deviceState);
- if (result != null) {
- return Collections.singleton(result);
- }
- return null;
+ return result;
}
}
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 953af6b33..cb658415c 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -15,8 +15,8 @@
*/
package org.traccar.events;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Map;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
@@ -37,18 +37,18 @@ public class OverspeedEventHandler extends BaseEventHandler {
this.minimalDuration = minimalDuration;
}
- private Event newEvent(DeviceState deviceState, double speedLimit) {
- Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, deviceState.getOverspeedPosition().getDeviceId(),
- deviceState.getOverspeedPosition().getId());
+ private Map<Event, Position> newEvent(DeviceState deviceState, double speedLimit) {
+ Position position = deviceState.getOverspeedPosition();
+ Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
event.set("speed", deviceState.getOverspeedPosition().getSpeed());
event.set(ATTRIBUTE_SPEED_LIMIT, speedLimit);
deviceState.setOverspeedState(notRepeat);
deviceState.setOverspeedPosition(null);
- return event;
+ return Collections.singletonMap(event, position);
}
- public Event updateOverspeedState(DeviceState deviceState, double speedLimit) {
- Event result = null;
+ public Map<Event, Position> updateOverspeedState(DeviceState deviceState, double speedLimit) {
+ Map<Event, Position> result = null;
if (deviceState.getOverspeedState() != null && !deviceState.getOverspeedState()
&& deviceState.getOverspeedPosition() != null && speedLimit != 0) {
long currentTime = System.currentTimeMillis();
@@ -61,8 +61,8 @@ public class OverspeedEventHandler extends BaseEventHandler {
return result;
}
- public Event updateOverspeedState(DeviceState deviceState, Position position, double speedLimit) {
- Event result = null;
+ public Map<Event, Position> updateOverspeedState(DeviceState deviceState, Position position, double speedLimit) {
+ Map<Event, Position> result = null;
Boolean oldOverspeed = deviceState.getOverspeedState();
@@ -89,7 +89,7 @@ public class OverspeedEventHandler extends BaseEventHandler {
}
@Override
- protected Collection<Event> analyzePosition(Position position) {
+ protected Map<Event, Position> analyzePosition(Position position) {
long deviceId = position.getDeviceId();
Device device = Context.getIdentityManager().getById(deviceId);
@@ -105,7 +105,7 @@ public class OverspeedEventHandler extends BaseEventHandler {
return null;
}
- Event result = null;
+ Map<Event, Position> result = null;
DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
if (deviceState.getOverspeedState() == null) {
@@ -115,10 +115,7 @@ public class OverspeedEventHandler extends BaseEventHandler {
}
Context.getDeviceManager().setDeviceState(deviceId, deviceState);
- if (result != null) {
- return Collections.singleton(result);
- }
- return null;
+ return result;
}
}
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 6a5370d15..46aea0757 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -46,6 +46,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.TimeZone;
public final class ReportUtils {
@@ -281,7 +282,7 @@ public final class ReportUtils {
int startEventIndex = trips == deviceState.getMotionState() ? 0 : -1;
int startNoEventIndex = -1;
for (int i = 0; i < positions.size(); i++) {
- Event event = motionHandler.updateMotionState(deviceState, positions.get(i),
+ Map<Event, Position> event = motionHandler.updateMotionState(deviceState, positions.get(i),
isMoving(positions, i, tripsConfig, speedThreshold));
if (deviceState.getMotionPosition() != null && startEventIndex == -1
&& trips != deviceState.getMotionState()) {
@@ -302,12 +303,10 @@ public final class ReportUtils {
startEventIndex = -1;
}
}
- if (startEventIndex != -1) {
- if (startNoEventIndex != -1 || !trips) {
- result.add(calculateTripOrStop(positions, startEventIndex,
+ if (startEventIndex != -1 && (startNoEventIndex != -1 || !trips)) {
+ result.add(calculateTripOrStop(positions, startEventIndex,
startNoEventIndex != -1 ? startNoEventIndex : positions.size() - 1,
ignoreOdometer, reportClass));
- }
}
}
return result;