aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-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
6 files changed, 100 insertions, 4 deletions
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);
}