aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
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
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')
-rw-r--r--src/org/traccar/database/DataManager.java18
-rw-r--r--src/org/traccar/database/IdentityManager.java2
2 files changed, 15 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) {
diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java
index c3861ad72..84f246363 100644
--- a/src/org/traccar/database/IdentityManager.java
+++ b/src/org/traccar/database/IdentityManager.java
@@ -19,6 +19,8 @@ import org.traccar.model.Device;
public interface IdentityManager {
+ public Device getDeviceById(long id);
+
public Device getDeviceByUniqueId(String uniqueId) throws Exception;
}