aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/GeofenceManager.java
diff options
context:
space:
mode:
authorninioe <ninioe@gmail.com>2016-07-24 10:12:29 +0300
committerninioe <ninioe@gmail.com>2016-07-24 10:12:29 +0300
commitefb18afb3bc265e0d3525ad66ee0e0558d95f478 (patch)
treef5d4cc82a144072a8eec0d25f9fb592422285e1f /src/org/traccar/database/GeofenceManager.java
parentfd3a695813f511d1b94775bd4e8a4c57053fc66d (diff)
parent0c61dddb5f875e34c819f6d936fcb5e7f45d88ed (diff)
downloadtrackermap-server-efb18afb3bc265e0d3525ad66ee0e0558d95f478.tar.gz
trackermap-server-efb18afb3bc265e0d3525ad66ee0e0558d95f478.tar.bz2
trackermap-server-efb18afb3bc265e0d3525ad66ee0e0558d95f478.zip
Merge remote-tracking branch 'refs/remotes/tananaev/master'
# Conflicts: # tools/test-generator.py
Diffstat (limited to 'src/org/traccar/database/GeofenceManager.java')
-rw-r--r--src/org/traccar/database/GeofenceManager.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index dc31172b9..74dff70f4 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -155,31 +155,41 @@ public class GeofenceManager {
public final void refresh() {
if (dataManager != null) {
try {
+
+ Collection<GroupGeofence> databaseGroupGeofences = dataManager.getGroupGeofences();
groupGeofencesLock.writeLock().lock();
- deviceGeofencesLock.writeLock().lock();
try {
groupGeofences.clear();
- for (GroupGeofence groupGeofence : dataManager.getGroupGeofences()) {
+ for (GroupGeofence groupGeofence : databaseGroupGeofences) {
getGroupGeofences(groupGeofence.getGroupId()).add(groupGeofence.getGeofenceId());
}
+ } finally {
+ groupGeofencesLock.writeLock().unlock();
+ }
+ Collection<DeviceGeofence> databaseDeviceGeofences = dataManager.getDeviceGeofences();
+ Collection<Device> allDevices = Context.getDeviceManager().getAllDevices();
+
+ groupGeofencesLock.readLock().lock();
+ deviceGeofencesLock.writeLock().lock();
+ try {
deviceGeofences.clear();
deviceGeofencesWithGroups.clear();
- for (DeviceGeofence deviceGeofence : dataManager.getDeviceGeofences()) {
+ for (DeviceGeofence deviceGeofence : databaseDeviceGeofences) {
getDeviceGeofences(deviceGeofences, deviceGeofence.getDeviceId())
.add(deviceGeofence.getGeofenceId());
getDeviceGeofences(deviceGeofencesWithGroups, deviceGeofence.getDeviceId())
.add(deviceGeofence.getGeofenceId());
}
- for (Device device : Context.getDeviceManager().getAllDevices()) {
+ for (Device device : allDevices) {
long groupId = device.getGroupId();
while (groupId != 0) {
getDeviceGeofences(deviceGeofencesWithGroups,
device.getId()).addAll(getGroupGeofences(groupId));
- if (dataManager.getGroupById(groupId) != null) {
- groupId = dataManager.getGroupById(groupId).getGroupId();
+ if (Context.getDeviceManager().getGroupById(groupId) != null) {
+ groupId = Context.getDeviceManager().getGroupById(groupId).getGroupId();
} else {
groupId = 0;
}
@@ -204,8 +214,8 @@ public class GeofenceManager {
}
} finally {
- groupGeofencesLock.writeLock().unlock();
deviceGeofencesLock.writeLock().unlock();
+ groupGeofencesLock.readLock().unlock();
}
} catch (SQLException error) {