aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-11-06 10:01:50 -0800
committerAnton Tananaev <anton@traccar.org>2022-11-06 10:01:50 -0800
commitd0df0c2e33034efee4a3a0705c92b09dbed5e291 (patch)
treefa41f83d8b14151f49bc3cb190b56132d436784e /src
parent21a916159a24db0cbec850b90381f9ff392f3c0e (diff)
downloadtrackermap-server-d0df0c2e33034efee4a3a0705c92b09dbed5e291.tar.gz
trackermap-server-d0df0c2e33034efee4a3a0705c92b09dbed5e291.tar.bz2
trackermap-server-d0df0c2e33034efee4a3a0705c92b09dbed5e291.zip
Handle missing cache
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java
index 8f2e7ba93..dc7382223 100644
--- a/src/main/java/org/traccar/session/cache/CacheManager.java
+++ b/src/main/java/org/traccar/session/cache/CacheManager.java
@@ -15,6 +15,8 @@
*/
package org.traccar.session.cache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.traccar.broadcast.BroadcastInterface;
import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
@@ -42,6 +44,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
@@ -57,6 +60,7 @@ import java.util.stream.Collectors;
@Singleton
public class CacheManager implements BroadcastInterface {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CacheManager.class);
private static final int GROUP_DEPTH_LIMIT = 3;
private static final Collection<Class<? extends BaseModel>> CLASSES = Arrays.asList(
Attribute.class, Driver.class, Geofence.class, Maintenance.class, Notification.class);
@@ -102,13 +106,19 @@ public class CacheManager implements BroadcastInterface {
public <T extends BaseModel> List<T> getDeviceObjects(long deviceId, Class<T> clazz) {
try {
lock.readLock().lock();
- return deviceLinks.get(deviceId).get(clazz).stream()
- .map(id -> {
- var cacheValue = deviceCache.get(new CacheKey(clazz, id));
- return cacheValue != null ? cacheValue.<T>getValue() : null;
- })
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
+ var links = deviceLinks.get(deviceId);
+ if (links != null) {
+ return links.getOrDefault(clazz, new LinkedHashSet<>()).stream()
+ .map(id -> {
+ var cacheValue = deviceCache.get(new CacheKey(clazz, id));
+ return cacheValue != null ? cacheValue.<T>getValue() : null;
+ })
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
+ } else {
+ LOGGER.warn("Device {} cache missing", deviceId);
+ return Collections.emptyList();
+ }
} finally {
lock.readLock().unlock();
}