diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-25 20:51:38 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-04-25 20:51:38 +1200 |
commit | b10cebd692b610a13ea27b6150a79726de59f40e (patch) | |
tree | 31919802ddae807fa4887446addc9eb98d5fbe50 /src/org/traccar/database/DataCache.java | |
parent | 67dc1c43932bffaf9df2c9ec201cff879d0226d9 (diff) | |
download | trackermap-server-b10cebd692b610a13ea27b6150a79726de59f40e.tar.gz trackermap-server-b10cebd692b610a13ea27b6150a79726de59f40e.tar.bz2 trackermap-server-b10cebd692b610a13ea27b6150a79726de59f40e.zip |
Implement async position update
Diffstat (limited to 'src/org/traccar/database/DataCache.java')
-rw-r--r-- | src/org/traccar/database/DataCache.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/org/traccar/database/DataCache.java b/src/org/traccar/database/DataCache.java index f5aa3b1e9..f28f1b838 100644 --- a/src/org/traccar/database/DataCache.java +++ b/src/org/traccar/database/DataCache.java @@ -18,6 +18,8 @@ package org.traccar.database; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import org.traccar.model.Position; @@ -31,7 +33,7 @@ public class DataCache { // TODO: load latest data from datavase } - public void update(Position position) { + public synchronized void update(Position position) { long device = position.getDeviceId(); positions.put(device, position); if (listeners.containsKey(device)) { @@ -41,6 +43,19 @@ public class DataCache { } } + public synchronized Collection<Position> getInitialState(Collection<Long> devices) { + + List<Position> result = new LinkedList<Position>(); + + for (long device : devices) { + if (positions.containsKey(device)) { + result.add(positions.get(device)); + } + } + + return result; + } + public static interface DataCacheListener { public void onUpdate(Position position); } @@ -51,7 +66,7 @@ public class DataCache { } } - public void addListener(long device, DataCacheListener listener) { + public synchronized void addListener(long device, DataCacheListener listener) { if (!listeners.containsKey(device)) { listeners.put(device, new HashSet<DataCacheListener>()); } @@ -64,7 +79,7 @@ public class DataCache { } } - public void removeListener(long device, DataCacheListener listener) { + public synchronized void removeListener(long device, DataCacheListener listener) { if (!listeners.containsKey(device)) { listeners.put(device, new HashSet<DataCacheListener>()); } |