aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-18 13:19:53 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-18 13:19:53 -0700
commit3a293661cd2900c115cfea6037c02d659c57aa52 (patch)
treede6f5f187af17b0272654016a6c2049c98f67d9a /src/main/java/org/traccar/database
parent589582c7ecc0d1cd5321cb6e9f4b823284369498 (diff)
downloadtrackermap-server-3a293661cd2900c115cfea6037c02d659c57aa52.tar.gz
trackermap-server-3a293661cd2900c115cfea6037c02d659c57aa52.tar.bz2
trackermap-server-3a293661cd2900c115cfea6037c02d659c57aa52.zip
Move device status
Diffstat (limited to 'src/main/java/org/traccar/database')
-rw-r--r--src/main/java/org/traccar/database/DataManager.java7
-rw-r--r--src/main/java/org/traccar/database/DeviceManager.java41
2 files changed, 2 insertions, 46 deletions
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index bfc79eb77..398c63892 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -16,7 +16,6 @@
package org.traccar.database;
import org.traccar.model.BaseModel;
-import org.traccar.model.Device;
import org.traccar.model.Server;
import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
@@ -36,12 +35,6 @@ public class DataManager {
this.storage = storage;
}
- public void updateDeviceStatus(Device device) throws StorageException {
- storage.updateObject(device, new Request(
- new Columns.Include("lastUpdate"),
- new Condition.Equals("id", "id")));
- }
-
public Server getServer() throws StorageException {
return storage.getObject(Server.class, new Request(new Columns.All()));
}
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);
- }
-
}