From f6333c73fe8bdd0027bb16a715193e1587b934a2 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 25 Jul 2016 08:59:36 +0500 Subject: - Move lastPosition update to the end of pipeline - Optimize MotionEventHandler to do not use Device.motion - Remove Device.motion from model and database - some optimizations --- debug.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index 2bd96021f..9520ce7ae 100644 --- a/debug.xml +++ b/debug.xml @@ -167,7 +167,7 @@ - UPDATE devices SET status = :status, lastUpdate = :lastUpdate, motion = :motion WHERE id = :id; + UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id; -- cgit v1.2.3 From 451c358879e1f6f2fda26e4b85ef97982fbeaba5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 25 Jul 2016 16:49:08 +1200 Subject: Improve history clearing logic --- debug.xml | 4 ++-- src/org/traccar/Main.java | 9 ++++----- src/org/traccar/database/DataManager.java | 27 +++++---------------------- 3 files changed, 11 insertions(+), 29 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index 346eda292..304ae7f3d 100644 --- a/debug.xml +++ b/debug.xml @@ -323,8 +323,8 @@ DELETE FROM notifications WHERE id = :id; - - DELETE FROM positions WHERE id != :positionId and deviceid = :deviceId and servertime < :serverTime; + + DELETE FROM positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM devices); diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java index e7e8d8ab9..e992691ad 100644 --- a/src/org/traccar/Main.java +++ b/src/org/traccar/Main.java @@ -23,8 +23,8 @@ import java.util.TimerTask; import java.util.Locale; public final class Main { - static final long CLEAN_DELAY = 0; - static final long CLEAN_PERIOD = 24 * 60 * 60 * 1000; + + private static final long CLEAN_PERIOD = 24 * 60 * 60 * 1000; private Main() { } @@ -40,8 +40,7 @@ public final class Main { Context.getWebServer().start(); } - Timer timer = new Timer(); - timer.scheduleAtFixedRate(new TimerTask() { + new Timer().scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { @@ -50,7 +49,7 @@ public final class Main { Log.warning(error); } } - }, CLEAN_DELAY, CLEAN_PERIOD); + }, 0, CLEAN_PERIOD); Runtime.getRuntime().addShutdownHook(new Thread() { @Override diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 04d0d44ea..78f1b4109 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -305,28 +305,11 @@ public class DataManager { } public void clearPositionsHistory() throws SQLException { - int histDays = config.getInteger("database.positionsHistoryDays"); - if (histDays == 0) { - return; - } - - String sql = getQuery("database.clearPositionsHistory"); - if (sql == null) { - return; - } - - for (Device device : getAllDevices()) { - Date lastUpdate = device.getLastUpdate(); - if (lastUpdate != null) { - - Date dateBefore = new Date(lastUpdate.getTime() - histDays * 24 * 3600 * 1000); - - QueryBuilder.create(dataSource, sql) - .setLong("positionId", device.getPositionId()) - .setLong("deviceId", device.getId()) - .setDate("serverTime", dateBefore) - .executeUpdate(); - } + int historyDays = config.getInteger("database.positionsHistoryDays"); + if (historyDays != 0) { + QueryBuilder.create(dataSource, getQuery("database.deletePositions")) + .setDate("serverTime", new Date(System.currentTimeMillis() - historyDays * 24 * 3600 * 1000)) + .executeUpdate(); } } -- cgit v1.2.3 From fb0a1689fda9a06ecf5e6a9a97ba8b2b704cacb9 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 25 Jul 2016 17:47:50 +0500 Subject: Added group and server attributes --- debug.xml | 7 +++--- schema/changelog-3.7.xml | 8 +++++++ setup/unix/traccar.xml | 7 +++--- setup/windows/traccar.xml | 7 +++--- src/org/traccar/model/Group.java | 12 +--------- src/org/traccar/model/Server.java | 12 +--------- swagger.json | 6 +++-- web/app/model/Group.js | 2 ++ web/app/model/Server.js | 2 ++ web/app/view/BaseEditDialog.js | 5 +++++ web/app/view/BaseEditDialogController.js | 14 ++++++++++++ web/app/view/DeviceDialog.js | 19 +++------------- web/app/view/DeviceDialogController.js | 38 -------------------------------- web/app/view/ServerDialog.js | 2 +- web/app/view/UserDialog.js | 13 ----------- web/app/view/UserDialogController.js | 20 +---------------- 16 files changed, 54 insertions(+), 120 deletions(-) delete mode 100644 web/app/view/DeviceDialogController.js (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index 095f7d4b2..f078a7e9d 100644 --- a/debug.xml +++ b/debug.xml @@ -102,7 +102,8 @@ latitude = :latitude, longitude = :longitude, zoom = :zoom, - twelveHourFormat = :twelveHourFormat + twelveHourFormat = :twelveHourFormat, + attributes = :attributes WHERE id = :id; @@ -190,11 +191,11 @@ - INSERT INTO groups (name, groupId) VALUES (:name, :groupId); + INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes); - UPDATE groups SET name = :name, groupId = :groupId WHERE id = :id; + UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id; diff --git a/schema/changelog-3.7.xml b/schema/changelog-3.7.xml index c988b8bdb..ae85f69f3 100644 --- a/schema/changelog-3.7.xml +++ b/schema/changelog-3.7.xml @@ -26,6 +26,14 @@ + + + + + + + + diff --git a/setup/unix/traccar.xml b/setup/unix/traccar.xml index 90cb5f74e..186e981cb 100644 --- a/setup/unix/traccar.xml +++ b/setup/unix/traccar.xml @@ -51,7 +51,8 @@ latitude = :latitude, longitude = :longitude, zoom = :zoom, - twelveHourFormat = :twelveHourFormat + twelveHourFormat = :twelveHourFormat, + attributes = :attributes WHERE id = :id; @@ -139,11 +140,11 @@ - INSERT INTO groups (name, groupId) VALUES (:name, :groupId); + INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes); - UPDATE groups SET name = :name, groupId = :groupId WHERE id = :id; + UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id; diff --git a/setup/windows/traccar.xml b/setup/windows/traccar.xml index 25128a3e0..aa3809763 100644 --- a/setup/windows/traccar.xml +++ b/setup/windows/traccar.xml @@ -51,7 +51,8 @@ latitude = :latitude, longitude = :longitude, zoom = :zoom, - twelveHourFormat = :twelveHourFormat + twelveHourFormat = :twelveHourFormat, + attributes = :attributes WHERE id = :id; @@ -139,11 +140,11 @@ - INSERT INTO groups (name, groupId) VALUES (:name, :groupId); + INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes); - UPDATE groups SET name = :name, groupId = :groupId WHERE id = :id; + UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id; diff --git a/src/org/traccar/model/Group.java b/src/org/traccar/model/Group.java index 00f2b2cfc..e70b3f3d5 100644 --- a/src/org/traccar/model/Group.java +++ b/src/org/traccar/model/Group.java @@ -15,17 +15,7 @@ */ package org.traccar.model; -public class Group { - - private long id; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +public class Group extends Extensible { private String name; diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java index 270fd61fa..b1557bf8f 100644 --- a/src/org/traccar/model/Server.java +++ b/src/org/traccar/model/Server.java @@ -15,17 +15,7 @@ */ package org.traccar.model; -public class Server { - - private long id; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } +public class Server extends Extensible { private boolean registration; diff --git a/swagger.json b/swagger.json index a16794a41..8b4157917 100644 --- a/swagger.json +++ b/swagger.json @@ -1235,7 +1235,8 @@ }, "twelveHourFormat": { "type": "boolean" - } + }, + "attributes": {} } }, "Command": { @@ -1286,7 +1287,8 @@ }, "groupId": { "type": "integer" - } + }, + "attributes": {} } }, "DevicePermission": { diff --git a/web/app/model/Group.js b/web/app/model/Group.js index a28897feb..bb18b5b3f 100644 --- a/web/app/model/Group.js +++ b/web/app/model/Group.js @@ -27,5 +27,7 @@ Ext.define('Traccar.model.Group', { }, { name: 'groupId', type: 'int' + }, { + name: 'attributes' }] }); diff --git a/web/app/model/Server.js b/web/app/model/Server.js index 3f6e466d9..02968c2d6 100644 --- a/web/app/model/Server.js +++ b/web/app/model/Server.js @@ -54,6 +54,8 @@ Ext.define('Traccar.model.Server', { }, { name: 'twelveHourFormat', type: 'boolean' + }, { + name: 'attributes' }], proxy: { diff --git a/web/app/view/BaseEditDialog.js b/web/app/view/BaseEditDialog.js index 051dfbe93..1af095c98 100644 --- a/web/app/view/BaseEditDialog.js +++ b/web/app/view/BaseEditDialog.js @@ -18,6 +18,11 @@ Ext.define('Traccar.view.BaseEditDialog', { extend: 'Traccar.view.BaseDialog', buttons: [{ + text: Strings.sharedAttributes, + handler: 'showAttributesView' + }, { + xtype: 'tbfill' + }, { text: Strings.sharedSave, handler: 'onSaveClick' }, { diff --git a/web/app/view/BaseEditDialogController.js b/web/app/view/BaseEditDialogController.js index 33bd01bd8..511309650 100644 --- a/web/app/view/BaseEditDialogController.js +++ b/web/app/view/BaseEditDialogController.js @@ -38,5 +38,19 @@ Ext.define('Traccar.view.BaseEditDialogController', { record.save(); } button.up('window').close(); + }, + + showAttributesView: function (button) { + var dialog, record; + dialog = button.up('window').down('form'); + record = dialog.getRecord(); + Ext.create('Traccar.view.BaseWindow', { + title: Strings.sharedAttributes, + modal: false, + items: { + xtype: 'attributesView', + record: record + } + }).show(); } }); diff --git a/web/app/view/DeviceDialog.js b/web/app/view/DeviceDialog.js index 2938d5dc3..e88618fc5 100644 --- a/web/app/view/DeviceDialog.js +++ b/web/app/view/DeviceDialog.js @@ -18,10 +18,10 @@ Ext.define('Traccar.view.DeviceDialog', { extend: 'Traccar.view.BaseEditDialog', requires: [ - 'Traccar.view.DeviceDialogController' + 'Traccar.view.BaseEditDialog' ], - controller: 'deviceDialog', + controller: 'baseEditDialog', title: Strings.deviceDialog, items: { @@ -45,18 +45,5 @@ Ext.define('Traccar.view.DeviceDialog', { displayField: 'name', valueField: 'id' }] - }, - - buttons: [{ - text : Strings.sharedAttributes, - handler: 'showAttributesView' - }, { - xtype: 'tbfill' - }, { - text: Strings.sharedSave, - handler: 'onSaveClick' - }, { - text: Strings.sharedCancel, - handler: 'closeView' - }] + } }); diff --git a/web/app/view/DeviceDialogController.js b/web/app/view/DeviceDialogController.js deleted file mode 100644 index 0a0f86883..000000000 --- a/web/app/view/DeviceDialogController.js +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -Ext.define('Traccar.view.DeviceDialogController', { - extend: 'Traccar.view.BaseEditDialogController', - alias: 'controller.deviceDialog', - - requires: [ - 'Traccar.view.Attributes' - ], - - showAttributesView: function (button) { - var dialog, record; - dialog = button.up('window').down('form'); - record = dialog.getRecord(); - Ext.create('Traccar.view.BaseWindow', { - title: Strings.sharedAttributes, - modal: false, - items: { - xtype: 'attributesView', - record: record - } - }).show(); - } -}); diff --git a/web/app/view/ServerDialog.js b/web/app/view/ServerDialog.js index 67f3a7ab2..1af000042 100644 --- a/web/app/view/ServerDialog.js +++ b/web/app/view/ServerDialog.js @@ -31,7 +31,7 @@ Ext.define('Traccar.view.ServerDialog', { name: 'registration', fieldLabel: Strings.serverRegistration, allowBlank: false - },{ + }, { xtype: 'checkboxfield', name: 'readonly', fieldLabel: Strings.serverReadonly, diff --git a/web/app/view/UserDialog.js b/web/app/view/UserDialog.js index 378cc0681..df8a26e7e 100644 --- a/web/app/view/UserDialog.js +++ b/web/app/view/UserDialog.js @@ -89,18 +89,5 @@ Ext.define('Traccar.view.UserDialog', { fieldLabel: Strings.settingsTwelveHourFormat, allowBlank: false }] - }], - - buttons: [{ - text : Strings.sharedAttributes, - handler: 'showAttributesView' - }, { - xtype: 'tbfill' - }, { - text: Strings.sharedSave, - handler: 'onSaveClick' - }, { - text: Strings.sharedCancel, - handler: 'closeView' }] }); diff --git a/web/app/view/UserDialogController.js b/web/app/view/UserDialogController.js index 49dfd9d70..c3a4ca62d 100644 --- a/web/app/view/UserDialogController.js +++ b/web/app/view/UserDialogController.js @@ -15,13 +15,9 @@ */ Ext.define('Traccar.view.UserDialogController', { - extend: 'Ext.app.ViewController', + extend: 'Traccar.view.BaseEditDialogController', alias: 'controller.userDialog', - requires: [ - 'Traccar.view.Attributes' - ], - init: function () { if (Traccar.app.getUser().get('admin')) { this.lookupReference('adminField').setDisabled(false); @@ -48,19 +44,5 @@ Ext.define('Traccar.view.UserDialogController', { }); } button.up('window').close(); - }, - - showAttributesView: function (button) { - var dialog, record; - dialog = button.up('window').down('form'); - record = dialog.getRecord(); - Ext.create('Traccar.view.BaseWindow', { - title: Strings.sharedAttributes, - modal: false, - items: { - xtype: 'attributesView', - record: record - } - }).show(); } }); -- cgit v1.2.3 From 60c442ac19776f0e07fafd1db8a0b75f971fd40e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 26 Jul 2016 14:50:32 +0500 Subject: Overspeed handler enhanced to use attributes --- debug.xml | 2 +- src/org/traccar/events/OverspeedEventHandler.java | 41 +++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index f078a7e9d..bd55b7ee1 100644 --- a/debug.xml +++ b/debug.xml @@ -44,7 +44,7 @@ true 60 true - 90 + true true true true diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index 6c9b523f4..b2b1aeb5f 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -24,16 +24,19 @@ import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; +import org.traccar.model.Server; import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; public class OverspeedEventHandler extends BaseEventHandler { - private double globalSpeedLimit; + public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit"; + + private boolean checkGroups; private int suppressRepeated; public OverspeedEventHandler() { - globalSpeedLimit = UnitsConverter.knotsFromKph(Context.getConfig().getInteger("event.globalSpeedLimit", 0)); + checkGroups = Context.getConfig().getBoolean("event.overspeed.groupsEnabled"); suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); } @@ -50,8 +53,40 @@ public class OverspeedEventHandler extends BaseEventHandler { Collection events = new ArrayList<>(); double speed = position.getSpeed(); + Double speedLimit = new Double(0); - if (globalSpeedLimit != 0 && speed > globalSpeedLimit) { + if (device.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) { + speedLimit = Double.parseDouble((String) device.getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); + } + if (speedLimit == 0 && checkGroups) { + long groupId = device.getGroupId(); + while (groupId != 0) { + if (Context.getDeviceManager().getGroupById(groupId).getAttributes() + .containsKey(ATTRIBUTE_SPEED_LIMIT)) { + speedLimit = Double.parseDouble((String) Context.getDeviceManager().getGroupById(groupId) + .getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); + if (speedLimit != 0) { + break; + } + } + if (Context.getDeviceManager().getGroupById(groupId) != null) { + groupId = Context.getDeviceManager().getGroupById(groupId).getGroupId(); + } else { + groupId = 0; + } + } + } + if (speedLimit == 0) { + try { + Server server = Context.getDataManager().getServer(); + if (server.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) { + speedLimit = Double.parseDouble((String) server.getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); + } + } catch (SQLException error) { + Log.warning(error); + } + } + if (speedLimit != 0 && speed > UnitsConverter.knotsFromKph(speedLimit)) { try { if (Context.getDataManager().getLastEvents( position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) { -- cgit v1.2.3 From 8ce7ef517c2913483eee7a09fd19e98cfd37b6e8 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 26 Jul 2016 15:22:03 +0500 Subject: Do not store device status in database --- debug.xml | 2 +- schema/changelog-3.7.xml | 2 ++ setup/unix/traccar.xml | 2 +- setup/windows/traccar.xml | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index bd55b7ee1..c08d46531 100644 --- a/debug.xml +++ b/debug.xml @@ -171,7 +171,7 @@ - UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id; + UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id; diff --git a/schema/changelog-3.7.xml b/schema/changelog-3.7.xml index ae85f69f3..d82dbe91b 100644 --- a/schema/changelog-3.7.xml +++ b/schema/changelog-3.7.xml @@ -26,6 +26,8 @@ + + diff --git a/setup/unix/traccar.xml b/setup/unix/traccar.xml index 186e981cb..da09d74d6 100644 --- a/setup/unix/traccar.xml +++ b/setup/unix/traccar.xml @@ -120,7 +120,7 @@ - UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id; + UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id; diff --git a/setup/windows/traccar.xml b/setup/windows/traccar.xml index aa3809763..a3971e4f8 100644 --- a/setup/windows/traccar.xml +++ b/setup/windows/traccar.xml @@ -120,7 +120,7 @@ - UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id; + UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id; -- cgit v1.2.3 From b00b35b33095110cef46c8a255686cad87ac7150 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 27 Jul 2016 11:31:39 +0500 Subject: Added option to rise event only once during overspeed period. --- debug.xml | 1 + src/org/traccar/events/OverspeedEventHandler.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index c08d46531..b33abc455 100644 --- a/debug.xml +++ b/debug.xml @@ -45,6 +45,7 @@ 60 true true + true true true true diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index e488b9df2..b61277548 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -33,10 +33,12 @@ public class OverspeedEventHandler extends BaseEventHandler { public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit"; private boolean checkGroups; + private boolean riseOnce; private int suppressRepeated; public OverspeedEventHandler() { checkGroups = Context.getConfig().getBoolean("event.overspeed.groupsEnabled"); + riseOnce = Context.getConfig().getBoolean("event.overspeed.riseOnce"); suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); } @@ -86,7 +88,15 @@ public class OverspeedEventHandler extends BaseEventHandler { Log.warning(error); } } - if (speedLimit != 0 && speed > UnitsConverter.knotsFromKph(speedLimit)) { + double oldSpeed = 0; + if (riseOnce) { + Position lastPosition = Context.getDeviceManager().getLastPosition(position.getDeviceId()); + if (lastPosition != null) { + oldSpeed = lastPosition.getSpeed(); + } + } + speedLimit = UnitsConverter.knotsFromKph(speedLimit); + if (speedLimit != 0 && speed > speedLimit && oldSpeed <= speedLimit) { try { if (Context.getDataManager().getLastEvents( position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) { @@ -95,7 +105,6 @@ public class OverspeedEventHandler extends BaseEventHandler { } catch (SQLException error) { Log.warning(error); } - } return events; } -- cgit v1.2.3 From b1e7bd492b9f6739936e533b4ab16d4825f1ce3c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 28 Jul 2016 14:35:02 +1200 Subject: Fix saving original raw binary data --- debug.xml | 2 +- src/org/traccar/ExtendedObjectDecoder.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index f078a7e9d..fab27920e 100644 --- a/debug.xml +++ b/debug.xml @@ -80,7 +80,7 @@ true false - false + true ./schema/changelog-master.xml diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java index d7ca30de4..1cfc93541 100644 --- a/src/org/traccar/ExtendedObjectDecoder.java +++ b/src/org/traccar/ExtendedObjectDecoder.java @@ -36,7 +36,8 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler { if (Context.getConfig().getBoolean("database.saveOriginal") && decodedMessage instanceof Position) { Position position = (Position) decodedMessage; if (originalMessage instanceof ChannelBuffer) { - position.set(Position.KEY_ORIGINAL, ChannelBuffers.hexDump((ChannelBuffer) originalMessage)); + ChannelBuffer buf = (ChannelBuffer) originalMessage; + position.set(Position.KEY_ORIGINAL, ChannelBuffers.hexDump(buf, 0, buf.writerIndex())); } else if (originalMessage instanceof String) { position.set(Position.KEY_ORIGINAL, DatatypeConverter.printHexBinary( ((String) originalMessage).getBytes(StandardCharsets.US_ASCII))); -- cgit v1.2.3 From f7e82c4d9a66b8ab1ba90d4cae690f9c798d03a7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 28 Jul 2016 11:42:10 +0500 Subject: Removed suppressing repeated events during analyzing. --- debug.xml | 1 - src/org/traccar/events/GeofenceEventHandler.java | 37 +++++------------------ src/org/traccar/events/MotionEventHandler.java | 32 ++++---------------- src/org/traccar/events/OverspeedEventHandler.java | 11 +------ 4 files changed, 15 insertions(+), 66 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index b33abc455..62e34d5d7 100644 --- a/debug.xml +++ b/debug.xml @@ -42,7 +42,6 @@ target/tracker-server.log true - 60 true true true diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index a9bed6f82..a0291dcfa 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -15,30 +15,23 @@ */ package org.traccar.events; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.traccar.BaseEventHandler; import org.traccar.Context; -import org.traccar.database.DataManager; import org.traccar.database.GeofenceManager; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; public class GeofenceEventHandler extends BaseEventHandler { - private int suppressRepeated; private GeofenceManager geofenceManager; - private DataManager dataManager; public GeofenceEventHandler() { - suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); geofenceManager = Context.getGeofenceManager(); - dataManager = Context.getDataManager(); } @Override @@ -63,29 +56,15 @@ public class GeofenceEventHandler extends BaseEventHandler { device.setGeofenceIds(currentGeofences); Collection events = new ArrayList<>(); - try { - if (dataManager.getLastEvents(position.getDeviceId(), - Event.TYPE_GEOFENCE_ENTER, suppressRepeated).isEmpty()) { - for (long geofenceId : newGeofences) { - Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId()); - event.setGeofenceId(geofenceId); - events.add(event); - } - } - } catch (SQLException error) { - Log.warning(error); + for (long geofenceId : newGeofences) { + Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId()); + event.setGeofenceId(geofenceId); + events.add(event); } - try { - if (dataManager.getLastEvents(position.getDeviceId(), - Event.TYPE_GEOFENCE_EXIT, suppressRepeated).isEmpty()) { - for (long geofenceId : oldGeofences) { - Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId()); - event.setGeofenceId(geofenceId); - events.add(event); - } - } - } catch (SQLException error) { - Log.warning(error); + for (long geofenceId : oldGeofences) { + Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId()); + event.setGeofenceId(geofenceId); + events.add(event); } return events; } diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 4b652a727..ddb99185f 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -15,13 +15,11 @@ */ package org.traccar.events; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import org.traccar.BaseEventHandler; import org.traccar.Context; -import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -29,11 +27,6 @@ import org.traccar.model.Position; public class MotionEventHandler extends BaseEventHandler { private static final double SPEED_THRESHOLD = 0.01; - private int suppressRepeated; - - public MotionEventHandler() { - suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); - } @Override protected Collection analyzePosition(Position position) { @@ -53,25 +46,12 @@ public class MotionEventHandler extends BaseEventHandler { if (lastPosition != null) { oldSpeed = lastPosition.getSpeed(); } - try { - if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) { - result = new ArrayList<>(); - result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); - } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) { - result = new ArrayList<>(); - result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); - } - - if (result != null && !result.isEmpty()) { - for (Event event : result) { - if (!Context.getDataManager().getLastEvents(position.getDeviceId(), - event.getType(), suppressRepeated).isEmpty()) { - event = null; - } - } - } - } catch (SQLException error) { - Log.warning(error); + if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) { + result = new ArrayList<>(); + result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); + } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) { + result = new ArrayList<>(); + result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); } return result; } diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index b61277548..0328b9109 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -34,12 +34,10 @@ public class OverspeedEventHandler extends BaseEventHandler { private boolean checkGroups; private boolean riseOnce; - private int suppressRepeated; public OverspeedEventHandler() { checkGroups = Context.getConfig().getBoolean("event.overspeed.groupsEnabled"); riseOnce = Context.getConfig().getBoolean("event.overspeed.riseOnce"); - suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60); } @Override @@ -97,14 +95,7 @@ public class OverspeedEventHandler extends BaseEventHandler { } speedLimit = UnitsConverter.knotsFromKph(speedLimit); if (speedLimit != 0 && speed > speedLimit && oldSpeed <= speedLimit) { - try { - if (Context.getDataManager().getLastEvents( - position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) { - events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId())); - } - } catch (SQLException error) { - Log.warning(error); - } + events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId())); } return events; } -- cgit v1.2.3 From 70f684945754b6bdadd2bf038ab955d93a95977d Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 28 Jul 2016 13:44:05 +0500 Subject: Organized server cache Moved lookupAttribute function to DeviceManager --- debug.xml | 3 +- src/org/traccar/api/resource/ServerResource.java | 5 ++- src/org/traccar/database/DeviceManager.java | 32 ++++++++++++++++++ src/org/traccar/database/PermissionsManager.java | 11 ++++++- src/org/traccar/events/OverspeedEventHandler.java | 40 +++-------------------- 5 files changed, 51 insertions(+), 40 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index 62e34d5d7..4c3b63d42 100644 --- a/debug.xml +++ b/debug.xml @@ -41,9 +41,10 @@ all target/tracker-server.log + true + true true - true true true true diff --git a/src/org/traccar/api/resource/ServerResource.java b/src/org/traccar/api/resource/ServerResource.java index 9e42687ab..0ca0d62aa 100644 --- a/src/org/traccar/api/resource/ServerResource.java +++ b/src/org/traccar/api/resource/ServerResource.java @@ -37,14 +37,13 @@ public class ServerResource extends BaseResource { @PermitAll @GET public Server get() throws SQLException { - return Context.getDataManager().getServer(); + return Context.getPermissionsManager().getServer(); } @PUT public Response update(Server entity) throws SQLException { Context.getPermissionsManager().checkAdmin(getUserId()); - Context.getDataManager().updateServer(entity); - Context.getPermissionsManager().refresh(); + Context.getPermissionsManager().updateServer(entity); return Response.ok(entity).build(); } diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index 5a0c87985..3476139f2 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -32,6 +32,7 @@ import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Group; import org.traccar.model.Position; +import org.traccar.model.Server; public class DeviceManager implements IdentityManager { @@ -40,6 +41,7 @@ public class DeviceManager implements IdentityManager { private final Config config; private final DataManager dataManager; private final long dataRefreshDelay; + private boolean lookupGroupsAttribute; private Map devicesById; private Map devicesByUniqueId; @@ -54,6 +56,7 @@ public class DeviceManager implements IdentityManager { this.dataManager = dataManager; this.config = Context.getConfig(); dataRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000; + lookupGroupsAttribute = config.getBoolean("deviceManager.lookupGroupsAttribute"); if (dataManager != null) { try { updateGroupCache(true); @@ -312,4 +315,33 @@ public class DeviceManager implements IdentityManager { dataManager.removeGroup(groupId); groupsById.remove(groupId); } + + public String lookupAttribute(long deviceId, String attributeName) { + String result = null; + Device device = getDeviceById(deviceId); + if (device != null) { + if (device.getAttributes().containsKey(attributeName)) { + result = (String) device.getAttributes().get(attributeName); + } + if (result == null && lookupGroupsAttribute) { + long groupId = device.getGroupId(); + while (groupId != 0) { + if (getGroupById(groupId) != null) { + result = (String) getGroupById(groupId).getAttributes().get(attributeName); + if (result != null) { + break; + } + groupId = getGroupById(groupId).getGroupId(); + } else { + groupId = 0; + } + } + } + if (result == null) { + Server server = Context.getPermissionsManager().getServer(); + result = (String) server.getAttributes().get(attributeName); + } + } + return result; + } } diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index d786dcc4e..92fcc3ebd 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -34,7 +34,7 @@ public class PermissionsManager { private final DataManager dataManager; - private Server server; + private volatile Server server; private final Map users = new HashMap<>(); @@ -153,4 +153,13 @@ public class PermissionsManager { } } + public Server getServer() { + return server; + } + + public void updateServer(Server server) throws SQLException { + dataManager.updateServer(server); + this.server = server; + } + } diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index 0328b9109..a1efbde48 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -15,7 +15,6 @@ */ package org.traccar.events; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; @@ -24,19 +23,15 @@ import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; -import org.traccar.model.Server; -import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; public class OverspeedEventHandler extends BaseEventHandler { public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit"; - private boolean checkGroups; private boolean riseOnce; public OverspeedEventHandler() { - checkGroups = Context.getConfig().getBoolean("event.overspeed.groupsEnabled"); riseOnce = Context.getConfig().getBoolean("event.overspeed.riseOnce"); } @@ -54,37 +49,12 @@ public class OverspeedEventHandler extends BaseEventHandler { Collection events = new ArrayList<>(); double speed = position.getSpeed(); double speedLimit = 0; - - if (device.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) { - speedLimit = Double.parseDouble((String) device.getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); - } - if (speedLimit == 0 && checkGroups) { - long groupId = device.getGroupId(); - while (groupId != 0) { - if (Context.getDeviceManager().getGroupById(groupId).getAttributes() - .containsKey(ATTRIBUTE_SPEED_LIMIT)) { - speedLimit = Double.parseDouble((String) Context.getDeviceManager().getGroupById(groupId) - .getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); - if (speedLimit != 0) { - break; - } - } - if (Context.getDeviceManager().getGroupById(groupId) != null) { - groupId = Context.getDeviceManager().getGroupById(groupId).getGroupId(); - } else { - groupId = 0; - } - } + String speedLimitAttribute = Context.getDeviceManager().lookupAttribute(device.getId(), ATTRIBUTE_SPEED_LIMIT); + if (speedLimitAttribute != null) { + speedLimit = Double.parseDouble(speedLimitAttribute); } if (speedLimit == 0) { - try { - Server server = Context.getDataManager().getServer(); - if (server.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) { - speedLimit = Double.parseDouble((String) server.getAttributes().get(ATTRIBUTE_SPEED_LIMIT)); - } - } catch (SQLException error) { - Log.warning(error); - } + return null; } double oldSpeed = 0; if (riseOnce) { @@ -94,7 +64,7 @@ public class OverspeedEventHandler extends BaseEventHandler { } } speedLimit = UnitsConverter.knotsFromKph(speedLimit); - if (speedLimit != 0 && speed > speedLimit && oldSpeed <= speedLimit) { + if (speed > speedLimit && oldSpeed <= speedLimit) { events.add(new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId())); } return events; -- cgit v1.2.3 From 6f89644fdcb3dbeb966cadbd810f9795922b8c4e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 28 Jul 2016 17:57:24 +0500 Subject: Rename parameter --- debug.xml | 2 +- src/org/traccar/events/OverspeedEventHandler.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'debug.xml') diff --git a/debug.xml b/debug.xml index 4c3b63d42..223378eac 100644 --- a/debug.xml +++ b/debug.xml @@ -45,7 +45,7 @@ true true - true + true true true true diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index a1efbde48..dbdb01ffb 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -29,10 +29,10 @@ public class OverspeedEventHandler extends BaseEventHandler { public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit"; - private boolean riseOnce; + private boolean notRepeat; public OverspeedEventHandler() { - riseOnce = Context.getConfig().getBoolean("event.overspeed.riseOnce"); + notRepeat = Context.getConfig().getBoolean("event.overspeed.notRepeat"); } @Override @@ -57,7 +57,7 @@ public class OverspeedEventHandler extends BaseEventHandler { return null; } double oldSpeed = 0; - if (riseOnce) { + if (notRepeat) { Position lastPosition = Context.getDeviceManager().getLastPosition(position.getDeviceId()); if (lastPosition != null) { oldSpeed = lastPosition.getSpeed(); -- cgit v1.2.3