aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-07 09:48:26 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-07 09:48:26 +1300
commit617df639c1835b1710115403efe180c8f1804f02 (patch)
treec20d7290714b3413a88566abfa97b02a9f22c2d1 /src/org/traccar
parent979314a9cfe4215fcf453759153bea67be4a7dd7 (diff)
downloadtrackermap-server-617df639c1835b1710115403efe180c8f1804f02.tar.gz
trackermap-server-617df639c1835b1710115403efe180c8f1804f02.tar.bz2
trackermap-server-617df639c1835b1710115403efe180c8f1804f02.zip
Refactor identity manager implementation
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/database/DataManager.java23
-rw-r--r--src/org/traccar/database/IdentityManager.java2
2 files changed, 13 insertions, 12 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 943dcb53c..deb31094e 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -111,17 +111,8 @@ public class DataManager implements IdentityManager {
}
}
- @Override
- public Device getDeviceById(long id) {
- return devicesById.get(id);
- }
-
- @Override
- public Device getDeviceByUniqueId(String uniqueId) throws SQLException {
-
- if (System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay
- || !devicesByUniqueId.containsKey(uniqueId)) {
-
+ private void updateDeviceCache(boolean force) throws SQLException {
+ if (System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay || force) {
devicesById.clear();
devicesByUniqueId.clear();
for (Device device : getAllDevices()) {
@@ -130,7 +121,17 @@ public class DataManager implements IdentityManager {
}
devicesLastUpdate = System.currentTimeMillis();
}
+ }
+ @Override
+ public Device getDeviceById(long id) throws SQLException {
+ updateDeviceCache(!devicesById.containsKey(id));
+ return devicesById.get(id);
+ }
+
+ @Override
+ public Device getDeviceByUniqueId(String uniqueId) throws SQLException {
+ updateDeviceCache(!devicesByUniqueId.containsKey(uniqueId));
return devicesByUniqueId.get(uniqueId);
}
diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java
index 8bdce09a3..761219dd5 100644
--- a/src/org/traccar/database/IdentityManager.java
+++ b/src/org/traccar/database/IdentityManager.java
@@ -19,7 +19,7 @@ import org.traccar.model.Device;
public interface IdentityManager {
- Device getDeviceById(long id);
+ Device getDeviceById(long id) throws Exception;
Device getDeviceByUniqueId(String uniqueId) throws Exception;