aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/geocoder/JsonGeocoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-18 14:12:05 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-18 14:12:05 -0700
commited64af90036d5e29b1e5fdf68df68c5c126beff7 (patch)
tree515f7695351df860a5c53b242e0a741413a491a7 /src/main/java/org/traccar/geocoder/JsonGeocoder.java
parent8ed8f8051b735a6f7c9480601e27339dbe8dab01 (diff)
downloadtrackermap-server-ed64af90036d5e29b1e5fdf68df68c5c126beff7.tar.gz
trackermap-server-ed64af90036d5e29b1e5fdf68df68c5c126beff7.tar.bz2
trackermap-server-ed64af90036d5e29b1e5fdf68df68c5c126beff7.zip
Fix geocoder injection
Diffstat (limited to 'src/main/java/org/traccar/geocoder/JsonGeocoder.java')
-rw-r--r--src/main/java/org/traccar/geocoder/JsonGeocoder.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/geocoder/JsonGeocoder.java b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
index 0262de18c..6105e8cfd 100644
--- a/src/main/java/org/traccar/geocoder/JsonGeocoder.java
+++ b/src/main/java/org/traccar/geocoder/JsonGeocoder.java
@@ -17,7 +17,6 @@ package org.traccar.geocoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.traccar.Main;
import org.traccar.database.StatisticsManager;
import javax.json.JsonObject;
@@ -36,6 +35,7 @@ public abstract class JsonGeocoder implements Geocoder {
private final Client client;
private final String url;
private final AddressFormat addressFormat;
+ private StatisticsManager statisticsManager;
private Map<Map.Entry<Double, Double>, String> cache;
@@ -44,7 +44,7 @@ public abstract class JsonGeocoder implements Geocoder {
this.url = url;
this.addressFormat = addressFormat;
if (cacheSize > 0) {
- this.cache = Collections.synchronizedMap(new LinkedHashMap<Map.Entry<Double, Double>, String>() {
+ this.cache = Collections.synchronizedMap(new LinkedHashMap<>() {
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > cacheSize;
@@ -53,6 +53,11 @@ public abstract class JsonGeocoder implements Geocoder {
}
}
+ @Override
+ public void setStatisticsManager(StatisticsManager statisticsManager) {
+ this.statisticsManager = statisticsManager;
+ }
+
protected String readValue(JsonObject object, String key) {
if (object.containsKey(key) && !object.isNull(key)) {
return object.getString(key);
@@ -98,8 +103,8 @@ public abstract class JsonGeocoder implements Geocoder {
}
}
- if (Main.getInjector() != null) {
- Main.getInjector().getInstance(StatisticsManager.class).registerGeocoderRequest();
+ if (statisticsManager != null) {
+ statisticsManager.registerGeocoderRequest();
}
var request = client.target(String.format(url, latitude, longitude)).request();