aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/ConnectionManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-17 13:46:03 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-17 13:46:03 +1300
commit5e56a1fbf80033cf5cc30ec7767d3cd92ab41cde (patch)
tree226c6af108c2f053fd28dc50b6b4bd633d5bea36 /src/org/traccar/database/ConnectionManager.java
parent3471e62b0f3949621265c80dcaf2ba714aade697 (diff)
downloadtrackermap-server-5e56a1fbf80033cf5cc30ec7767d3cd92ab41cde.tar.gz
trackermap-server-5e56a1fbf80033cf5cc30ec7767d3cd92ab41cde.tar.bz2
trackermap-server-5e56a1fbf80033cf5cc30ec7767d3cd92ab41cde.zip
Update device status via async web service
Diffstat (limited to 'src/org/traccar/database/ConnectionManager.java')
-rw-r--r--src/org/traccar/database/ConnectionManager.java28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index cb7b4b6d8..345bb4577 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -36,13 +36,13 @@ public class ConnectionManager {
private final Map<Long, ActiveDevice> activeDevices = new HashMap<>();
private final Map<Long, Position> positions = new HashMap<>();
- private final Map<Long, Set<DataCacheListener>> listeners = new HashMap<>();
+ private final Map<Long, Set<UpdateListener>> listeners = new HashMap<>();
public ConnectionManager(DataManager dataManager) {
if (dataManager != null) {
try {
for (Position position : dataManager.getLatestPositions()) {
- this.positions.put(position.getDeviceId(), position);
+ positions.put(position.getDeviceId(), position);
}
} catch (SQLException error) {
Log.warning(error);
@@ -79,14 +79,19 @@ public class ConnectionManager {
Log.warning(error);
}
- // TODO call listener
+ if (listeners.containsKey(deviceId)) {
+ for (UpdateListener listener : listeners.get(deviceId)) {
+ listener.onUpdateDevice(device);
+ }
+ }
}
public synchronized void updatePosition(Position position) {
long deviceId = position.getDeviceId();
positions.put(deviceId, position);
+
if (listeners.containsKey(deviceId)) {
- for (DataCacheListener listener : listeners.get(deviceId)) {
+ for (UpdateListener listener : listeners.get(deviceId)) {
listener.onUpdatePosition(position);
}
}
@@ -109,32 +114,33 @@ public class ConnectionManager {
return result;
}
- public interface DataCacheListener {
+ public interface UpdateListener {
+ void onUpdateDevice(Device device);
void onUpdatePosition(Position position);
}
- public void addListener(Collection<Long> devices, DataCacheListener listener) {
+ public void addListener(Collection<Long> devices, UpdateListener listener) {
for (long deviceId : devices) {
addListener(deviceId, listener);
}
}
- public synchronized void addListener(long deviceId, DataCacheListener listener) {
+ public synchronized void addListener(long deviceId, UpdateListener listener) {
if (!listeners.containsKey(deviceId)) {
- listeners.put(deviceId, new HashSet<DataCacheListener>());
+ listeners.put(deviceId, new HashSet<UpdateListener>());
}
listeners.get(deviceId).add(listener);
}
- public void removeListener(Collection<Long> devices, DataCacheListener listener) {
+ public void removeListener(Collection<Long> devices, UpdateListener listener) {
for (long deviceId : devices) {
removeListener(deviceId, listener);
}
}
- public synchronized void removeListener(long deviceId, DataCacheListener listener) {
+ public synchronized void removeListener(long deviceId, UpdateListener listener) {
if (!listeners.containsKey(deviceId)) {
- listeners.put(deviceId, new HashSet<DataCacheListener>());
+ listeners.put(deviceId, new HashSet<UpdateListener>());
}
listeners.get(deviceId).remove(listener);
}