aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/SpeedLimitHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/handler/SpeedLimitHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/SpeedLimitHandler.java49
1 files changed, 19 insertions, 30 deletions
diff --git a/src/main/java/org/traccar/handler/SpeedLimitHandler.java b/src/main/java/org/traccar/handler/SpeedLimitHandler.java
index 6edb6e912..604c10ca7 100644
--- a/src/main/java/org/traccar/handler/SpeedLimitHandler.java
+++ b/src/main/java/org/traccar/handler/SpeedLimitHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2020 - 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,20 +15,13 @@
*/
package org.traccar.handler;
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
+import jakarta.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.model.Position;
import org.traccar.speedlimit.SpeedLimitProvider;
-import jakarta.inject.Inject;
-import jakarta.inject.Singleton;
-
-@Singleton
-@ChannelHandler.Sharable
-public class SpeedLimitHandler extends ChannelInboundHandlerAdapter {
+public class SpeedLimitHandler extends BasePositionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(SpeedLimitHandler.class);
@@ -40,26 +33,22 @@ public class SpeedLimitHandler extends ChannelInboundHandlerAdapter {
}
@Override
- public void channelRead(final ChannelHandlerContext ctx, Object message) {
- if (message instanceof Position) {
- final Position position = (Position) message;
- speedLimitProvider.getSpeedLimit(position.getLatitude(), position.getLongitude(),
- new SpeedLimitProvider.SpeedLimitProviderCallback() {
- @Override
- public void onSuccess(double speedLimit) {
- position.set(Position.KEY_SPEED_LIMIT, speedLimit);
- ctx.fireChannelRead(position);
- }
-
- @Override
- public void onFailure(Throwable e) {
- LOGGER.warn("Speed limit provider failed", e);
- ctx.fireChannelRead(position);
- }
- });
- } else {
- ctx.fireChannelRead(message);
- }
+ public void handlePosition(Position position, Callback callback) {
+
+ speedLimitProvider.getSpeedLimit(position.getLatitude(), position.getLongitude(),
+ new SpeedLimitProvider.SpeedLimitProviderCallback() {
+ @Override
+ public void onSuccess(double speedLimit) {
+ position.set(Position.KEY_SPEED_LIMIT, speedLimit);
+ callback.processed(position);
+ }
+
+ @Override
+ public void onFailure(Throwable e) {
+ LOGGER.warn("Speed limit provider failed", e);
+ callback.processed(position);
+ }
+ });
}
}