aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/GeocoderHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-03-30 18:46:37 -0700
committerAnton Tananaev <anton@traccar.org>2024-03-30 18:46:37 -0700
commitf84e2710e05660822633ec9e61cde44c03a42d7e (patch)
tree0d68bee50cc42ed206d270275dfb32b4b69c5186 /src/main/java/org/traccar/handler/GeocoderHandler.java
parentee996425221ca64fdf00777d9035cedc6dccfa43 (diff)
downloadtrackermap-server-f84e2710e05660822633ec9e61cde44c03a42d7e.tar.gz
trackermap-server-f84e2710e05660822633ec9e61cde44c03a42d7e.tar.bz2
trackermap-server-f84e2710e05660822633ec9e61cde44c03a42d7e.zip
Refactor position and event handlers
Diffstat (limited to 'src/main/java/org/traccar/handler/GeocoderHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/GeocoderHandler.java65
1 files changed, 30 insertions, 35 deletions
diff --git a/src/main/java/org/traccar/handler/GeocoderHandler.java b/src/main/java/org/traccar/handler/GeocoderHandler.java
index e4f240a90..c62bcb6f8 100644
--- a/src/main/java/org/traccar/handler/GeocoderHandler.java
+++ b/src/main/java/org/traccar/handler/GeocoderHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2024 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.
@@ -15,9 +15,6 @@
*/
package org.traccar.handler;
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.config.Config;
@@ -26,8 +23,7 @@ import org.traccar.geocoder.Geocoder;
import org.traccar.model.Position;
import org.traccar.session.cache.CacheManager;
-@ChannelHandler.Sharable
-public class GeocoderHandler extends ChannelInboundHandlerAdapter {
+public class GeocoderHandler extends BasePositionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(GeocoderHandler.class);
@@ -46,39 +42,38 @@ public class GeocoderHandler extends ChannelInboundHandlerAdapter {
}
@Override
- public void channelRead(final ChannelHandlerContext ctx, Object message) {
- if (message instanceof Position && !ignorePositions) {
- final Position position = (Position) message;
- if (processInvalidPositions || position.getValid()) {
- if (reuseDistance != 0) {
- Position lastPosition = cacheManager.getPosition(position.getDeviceId());
- if (lastPosition != null && lastPosition.getAddress() != null
- && position.getDouble(Position.KEY_DISTANCE) <= reuseDistance) {
- position.setAddress(lastPosition.getAddress());
- ctx.fireChannelRead(position);
- return;
- }
+ public void handlePosition(Position position, Callback callback) {
+ if (!ignorePositions) {
+ callback.processed(position);
+ }
+
+ if (processInvalidPositions || position.getValid()) {
+ if (reuseDistance != 0) {
+ Position lastPosition = cacheManager.getPosition(position.getDeviceId());
+ if (lastPosition != null && lastPosition.getAddress() != null
+ && position.getDouble(Position.KEY_DISTANCE) <= reuseDistance) {
+ position.setAddress(lastPosition.getAddress());
+ callback.processed(position);
+ return;
}
+ }
- geocoder.getAddress(position.getLatitude(), position.getLongitude(),
- new Geocoder.ReverseGeocoderCallback() {
- @Override
- public void onSuccess(String address) {
- position.setAddress(address);
- ctx.fireChannelRead(position);
- }
+ geocoder.getAddress(position.getLatitude(), position.getLongitude(),
+ new Geocoder.ReverseGeocoderCallback() {
+ @Override
+ public void onSuccess(String address) {
+ position.setAddress(address);
+ callback.processed(position);
+ }
- @Override
- public void onFailure(Throwable e) {
- LOGGER.warn("Geocoding failed", e);
- ctx.fireChannelRead(position);
- }
- });
- } else {
- ctx.fireChannelRead(position);
- }
+ @Override
+ public void onFailure(Throwable e) {
+ LOGGER.warn("Geocoding failed", e);
+ callback.processed(position);
+ }
+ });
} else {
- ctx.fireChannelRead(message);
+ callback.processed(position);
}
}