aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DataManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-07-14 19:17:02 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-07-14 19:17:02 +1200
commite98b18b8b0a8c99d24ac8010c1393978d071baa2 (patch)
tree48d63f067dcfaae9c0bdac34af4f9514a49ab9f5 /src/org/traccar/database/DataManager.java
parent7310ee5f15729ea8517bfb6b0890a46da1217610 (diff)
downloadtrackermap-server-e98b18b8b0a8c99d24ac8010c1393978d071baa2.tar.gz
trackermap-server-e98b18b8b0a8c99d24ac8010c1393978d071baa2.tar.bz2
trackermap-server-e98b18b8b0a8c99d24ac8010c1393978d071baa2.zip
Support forwarding of data (fix #1131)
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r--src/org/traccar/database/DataManager.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 48f3228ce..f134f87cb 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -50,7 +50,8 @@ public class DataManager implements IdentityManager {
private DataSource dataSource;
- private final Map<String, Device> devices = new HashMap<>();
+ private final Map<Long, Device> devicesById = new HashMap<>();
+ private final Map<String, Device> devicesByUniqueId = new HashMap<>();
private long devicesLastUpdate;
private final long devicesRefreshDelay;
@@ -107,20 +108,27 @@ public class DataManager implements IdentityManager {
dataSource = ds;
}
}
+
+ @Override
+ public Device getDeviceById(long id) {
+ return devicesById.get(id);
+ }
@Override
public Device getDeviceByUniqueId(String uniqueId) throws SQLException {
- if ((new Date().getTime() - devicesLastUpdate > devicesRefreshDelay) || !devices.containsKey(uniqueId)) {
+ if ((new Date().getTime() - devicesLastUpdate > devicesRefreshDelay) || !devicesByUniqueId.containsKey(uniqueId)) {
- devices.clear();
+ devicesById.clear();
+ devicesByUniqueId.clear();
for (Device device : getAllDevices()) {
- devices.put(device.getUniqueId(), device);
+ devicesById.put(device.getId(), device);
+ devicesByUniqueId.put(device.getUniqueId(), device);
}
devicesLastUpdate = new Date().getTime();
}
- return devices.get(uniqueId);
+ return devicesByUniqueId.get(uniqueId);
}
private String getQuery(String key) {