aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--schema/changelog-3.12.xml28
-rw-r--r--schema/changelog-master.xml1
-rw-r--r--setup/default.xml4
-rw-r--r--src/org/traccar/GeocoderHandler.java22
-rw-r--r--src/org/traccar/GeolocationHandler.java4
-rw-r--r--src/org/traccar/database/StatisticsManager.java34
-rw-r--r--src/org/traccar/model/Statistics.java41
-rw-r--r--src/org/traccar/notification/NotificationMail.java1
-rw-r--r--src/org/traccar/notification/NotificationSms.java2
9 files changed, 131 insertions, 6 deletions
diff --git a/schema/changelog-3.12.xml b/schema/changelog-3.12.xml
new file mode 100644
index 000000000..43c0e33f0
--- /dev/null
+++ b/schema/changelog-3.12.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
+ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"
+ logicalFilePath="changelog-3.12">
+
+ <changeSet author="author" id="changelog-3.12">
+
+ <addColumn tableName="statistics">
+ <column name="mailsent" type="INT" defaultValueNumeric="0">
+ <constraints nullable="false" />
+ </column>
+ <column name="smssent" type="INT" defaultValueNumeric="0">
+ <constraints nullable="false" />
+ </column>
+ <column name="geocoderrequests" type="INT" defaultValueNumeric="0">
+ <constraints nullable="false" />
+ </column>
+ <column name="geolocationrequests" type="INT" defaultValueNumeric="0">
+ <constraints nullable="false" />
+ </column>
+ </addColumn>
+
+ </changeSet>
+
+</databaseChangeLog>
diff --git a/schema/changelog-master.xml b/schema/changelog-master.xml
index eaa5324f1..ba93d105f 100644
--- a/schema/changelog-master.xml
+++ b/schema/changelog-master.xml
@@ -13,4 +13,5 @@
<include file="changelog-3.9.xml" relativeToChangelogFile="true" />
<include file="changelog-3.10.xml" relativeToChangelogFile="true" />
<include file="changelog-3.11.xml" relativeToChangelogFile="true" />
+ <include file="changelog-3.12.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
diff --git a/setup/default.xml b/setup/default.xml
index e369ad9f0..82f2798dd 100644
--- a/setup/default.xml
+++ b/setup/default.xml
@@ -315,8 +315,8 @@
</entry>
<entry key='database.insertStatistics'>
- INSERT INTO statistics (captureTime, activeUsers, activeDevices, requests, messagesReceived, messagesStored, attributes)
- VALUES (:captureTime, :activeUsers, :activeDevices, :requests, :messagesReceived, :messagesStored, :attributes)
+ INSERT INTO statistics (captureTime, activeUsers, activeDevices, requests, messagesReceived, messagesStored, mailSent, smsSent, geocoderRequests, geolocationRequests, attributes)
+ VALUES (:captureTime, :activeUsers, :activeDevices, :requests, :messagesReceived, :messagesStored, :mailSent, :smsSent, :geocoderRequests, :geolocationRequests, :attributes)
</entry>
<entry key='database.selectCalendarsAll'>
diff --git a/src/org/traccar/GeocoderHandler.java b/src/org/traccar/GeocoderHandler.java
index 8933cadac..c5f4d2f9a 100644
--- a/src/org/traccar/GeocoderHandler.java
+++ b/src/org/traccar/GeocoderHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
import org.traccar.geocoder.AddressFormat;
import org.traccar.geocoder.Geocoder;
+import org.traccar.helper.DistanceCalculator;
import org.traccar.helper.Log;
import org.traccar.model.Position;
@@ -30,6 +31,7 @@ public class GeocoderHandler implements ChannelUpstreamHandler {
private final Geocoder geocoder;
private final boolean processInvalidPositions;
private final AddressFormat addressFormat;
+ private final int geocoderReuseDistance;
public GeocoderHandler(Geocoder geocoder, boolean processInvalidPositions) {
this.geocoder = geocoder;
@@ -41,6 +43,8 @@ public class GeocoderHandler implements ChannelUpstreamHandler {
} else {
addressFormat = new AddressFormat();
}
+
+ geocoderReuseDistance = Context.getConfig().getInteger("geocoder.reuseDistance", 0);
}
@Override
@@ -55,6 +59,22 @@ public class GeocoderHandler implements ChannelUpstreamHandler {
if (message instanceof Position) {
final Position position = (Position) message;
if (processInvalidPositions || position.getValid()) {
+ if (geocoderReuseDistance != 0) {
+ Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ if (lastPosition != null && lastPosition.getAddress() != null) {
+ double distance = DistanceCalculator.distance(
+ position.getLatitude(), position.getLongitude(),
+ lastPosition.getLatitude(), lastPosition.getLongitude());
+ if (distance <= geocoderReuseDistance) {
+ position.setAddress(lastPosition.getAddress());
+ Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
+ return;
+ }
+ }
+ }
+
+ Context.getStatisticsManager().registerGeocoderRequest();
+
geocoder.getAddress(addressFormat, position.getLatitude(), position.getLongitude(),
new Geocoder.ReverseGeocoderCallback() {
@Override
diff --git a/src/org/traccar/GeolocationHandler.java b/src/org/traccar/GeolocationHandler.java
index 31fed5dbd..346ad5904 100644
--- a/src/org/traccar/GeolocationHandler.java
+++ b/src/org/traccar/GeolocationHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,6 +47,8 @@ public class GeolocationHandler implements ChannelUpstreamHandler {
final Position position = (Position) message;
if ((position.getOutdated() || processInvalidPositions && !position.getValid())
&& position.getNetwork() != null) {
+ Context.getStatisticsManager().registerGeolocationRequest();
+
geolocationProvider.getLocation(position.getNetwork(),
new GeolocationProvider.LocationProviderCallback() {
@Override
diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java
index 5b0aa5f41..8abadddc5 100644
--- a/src/org/traccar/database/StatisticsManager.java
+++ b/src/org/traccar/database/StatisticsManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,10 @@ public class StatisticsManager {
private int requests;
private int messagesReceived;
private int messagesStored;
+ private int mailSent;
+ private int smsSent;
+ private int geocoderRequests;
+ private int geolocationRequests;
private void checkSplit() {
int currentUpdate = Calendar.getInstance().get(SPLIT_MODE);
@@ -48,6 +52,10 @@ public class StatisticsManager {
statistics.setRequests(requests);
statistics.setMessagesReceived(messagesReceived);
statistics.setMessagesStored(messagesStored);
+ statistics.setMailSent(mailSent);
+ statistics.setSmsSent(smsSent);
+ statistics.setGeocoderRequests(geocoderRequests);
+ statistics.setGeolocationRequests(geolocationRequests);
try {
Context.getDataManager().addStatistics(statistics);
@@ -60,6 +68,10 @@ public class StatisticsManager {
requests = 0;
messagesReceived = 0;
messagesStored = 0;
+ mailSent = 0;
+ smsSent = 0;
+ geocoderRequests = 0;
+ geolocationRequests = 0;
lastUpdate = currentUpdate;
}
}
@@ -85,4 +97,24 @@ public class StatisticsManager {
}
}
+ public synchronized void registerMail() {
+ checkSplit();
+ mailSent += 1;
+ }
+
+ public synchronized void registerSms() {
+ checkSplit();
+ smsSent += 1;
+ }
+
+ public synchronized void registerGeocoderRequest() {
+ checkSplit();
+ geocoderRequests += 1;
+ }
+
+ public synchronized void registerGeolocationRequest() {
+ checkSplit();
+ geolocationRequests += 1;
+ }
+
}
diff --git a/src/org/traccar/model/Statistics.java b/src/org/traccar/model/Statistics.java
index f458ddfad..93a9c0d39 100644
--- a/src/org/traccar/model/Statistics.java
+++ b/src/org/traccar/model/Statistics.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,4 +87,43 @@ public class Statistics extends Extensible {
this.messagesStored = messagesStored;
}
+ private int mailSent;
+
+ public int getMailSent() {
+ return mailSent;
+ }
+
+ public void setMailSent(int mailSent) {
+ this.mailSent = mailSent;
+ }
+
+ private int smsSent;
+
+ public int getSmsSent() {
+ return smsSent;
+ }
+
+ public void setSmsSent(int smsSent) {
+ this.smsSent = smsSent;
+ }
+
+ private int geocoderRequests;
+
+ public int getGeocoderRequests() {
+ return geocoderRequests;
+ }
+
+ public void setGeocoderRequests(int geocoderRequests) {
+ this.geocoderRequests = geocoderRequests;
+ }
+ private int geolocationRequests;
+
+ public int getGeolocationRequests() {
+ return geolocationRequests;
+ }
+
+ public void setGeolocationRequests(int geolocationRequests) {
+ this.geolocationRequests = geolocationRequests;
+ }
+
}
diff --git a/src/org/traccar/notification/NotificationMail.java b/src/org/traccar/notification/NotificationMail.java
index c31a02b32..115b109e6 100644
--- a/src/org/traccar/notification/NotificationMail.java
+++ b/src/org/traccar/notification/NotificationMail.java
@@ -115,6 +115,7 @@ public final class NotificationMail {
Transport transport = session.getTransport();
try {
+ Context.getStatisticsManager().registerMail();
transport.connect(
properties.getProperty("mail.smtp.host"),
properties.getProperty("mail.smtp.username"),
diff --git a/src/org/traccar/notification/NotificationSms.java b/src/org/traccar/notification/NotificationSms.java
index 7b265e3ce..8c0265af4 100644
--- a/src/org/traccar/notification/NotificationSms.java
+++ b/src/org/traccar/notification/NotificationSms.java
@@ -34,6 +34,7 @@ public final class NotificationSms {
public static void sendSmsAsync(long userId, Event event, Position position) {
User user = Context.getPermissionsManager().getUser(userId);
if (Context.getSmppManager() != null && user.getPhone() != null) {
+ Context.getStatisticsManager().registerSms();
Context.getSmppManager().sendMessageAsync(user.getPhone(),
NotificationFormatter.formatSmsMessage(userId, event, position), false);
}
@@ -43,6 +44,7 @@ public final class NotificationSms {
UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {
User user = Context.getPermissionsManager().getUser(userId);
if (Context.getSmppManager() != null && user.getPhone() != null) {
+ Context.getStatisticsManager().registerSms();
Context.getSmppManager().sendMessageSync(user.getPhone(),
NotificationFormatter.formatSmsMessage(userId, event, position), false);
}