aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/events
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-08-17 10:10:05 +0500
committerAbyss777 <abyss@fox5.ru>2017-08-17 10:10:05 +0500
commit1324c00d0ece6e20545fb75f7775a2c6cee2a391 (patch)
tree775ad2a42ebba160d1e36be38c59384cd1da5a1e /src/org/traccar/events
parent9476e6be8fae228cda5867750bc4d102b1f9497d (diff)
downloadtraccar-server-1324c00d0ece6e20545fb75f7775a2c6cee2a391.tar.gz
traccar-server-1324c00d0ece6e20545fb75f7775a2c6cee2a391.tar.bz2
traccar-server-1324c00d0ece6e20545fb75f7775a2c6cee2a391.zip
Pass Map<Event, Position> to notifications
Diffstat (limited to 'src/org/traccar/events')
-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
9 files changed, 53 insertions, 58 deletions
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;
}
}