diff options
Diffstat (limited to 'src/main/java/org/traccar/database/DeviceManager.java')
-rw-r--r-- | src/main/java/org/traccar/database/DeviceManager.java | 41 |
1 files changed, 2 insertions, 39 deletions
diff --git a/src/main/java/org/traccar/database/DeviceManager.java b/src/main/java/org/traccar/database/DeviceManager.java index d6c442f10..7a472c2d4 100644 --- a/src/main/java/org/traccar/database/DeviceManager.java +++ b/src/main/java/org/traccar/database/DeviceManager.java @@ -15,34 +15,22 @@ */ package org.traccar.database; -import org.traccar.config.Config; -import org.traccar.config.Keys; import org.traccar.model.Device; -import org.traccar.session.DeviceState; -import org.traccar.storage.StorageException; -import java.util.Collection; -import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; public class DeviceManager extends BaseObjectManager<Device> { - private final long dataRefreshDelay; - private final AtomicLong devicesLastUpdate = new AtomicLong(); - private final Map<Long, DeviceState> deviceStates = new ConcurrentHashMap<>(); - - public DeviceManager(Config config, DataManager dataManager) { + public DeviceManager(DataManager dataManager) { super(dataManager, Device.class); - dataRefreshDelay = config.getLong(Keys.DATABASE_REFRESH_DELAY) * 1000; } public void updateDeviceCache(boolean force) { long lastUpdate = devicesLastUpdate.get(); - if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay) + if ((force || System.currentTimeMillis() - lastUpdate > 300000L) && devicesLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) { refreshItems(); } @@ -58,10 +46,6 @@ public class DeviceManager extends BaseObjectManager<Device> { return result; } - public Collection<Device> getAllDevices() { - return getItems(getAllItems()); - } - @Override protected void updateCachedItem(Device device) { Device cachedDevice = getById(device.getId()); @@ -84,25 +68,4 @@ public class DeviceManager extends BaseObjectManager<Device> { } } - public void updateDeviceStatus(Device device) throws StorageException { - getDataManager().updateDeviceStatus(device); - Device cachedDevice = getById(device.getId()); - if (cachedDevice != null) { - cachedDevice.setStatus(device.getStatus()); - } - } - - public DeviceState getDeviceState(long deviceId) { - DeviceState deviceState = deviceStates.get(deviceId); - if (deviceState == null) { - deviceState = new DeviceState(); - deviceStates.put(deviceId, deviceState); - } - return deviceState; - } - - public void setDeviceState(long deviceId, DeviceState deviceState) { - deviceStates.put(deviceId, deviceState); - } - } |