aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-24 18:06:39 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-24 18:06:39 -0800
commit041c2b897c28dc316e8613c9ea38dee48dd64482 (patch)
tree2aeee13384c6927dfb734e84fce6dced8fa62c5f
parentd610b1ab5135503d1d39aa291190a860ddb952a9 (diff)
downloadtrackermap-server-041c2b897c28dc316e8613c9ea38dee48dd64482.tar.gz
trackermap-server-041c2b897c28dc316e8613c9ea38dee48dd64482.tar.bz2
trackermap-server-041c2b897c28dc316e8613c9ea38dee48dd64482.zip
Refactor motion handler
-rw-r--r--src/org/traccar/BasePipelineFactory.java6
-rw-r--r--src/org/traccar/MainModule.java13
-rw-r--r--src/org/traccar/handler/MotionHandler.java (renamed from src/org/traccar/MotionHandler.java)5
-rw-r--r--test/org/traccar/handler/MotionHandlerTest.java (renamed from test/org/traccar/MotionHandlerTest.java)4
4 files changed, 20 insertions, 8 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 8e6a62391..cb60b20a7 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -41,6 +41,7 @@ import org.traccar.handler.FilterHandler;
import org.traccar.handler.GeocoderHandler;
import org.traccar.handler.GeolocationHandler;
import org.traccar.handler.HemisphereHandler;
+import org.traccar.handler.MotionHandler;
import org.traccar.handler.NetworkMessageHandler;
import org.traccar.handler.OpenChannelHandler;
import org.traccar.handler.RemoteAddressHandler;
@@ -56,7 +57,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
private int timeout;
private EngineHoursHandler engineHoursHandler;
- private MotionHandler motionHandler;
private CopyAttributesHandler copyAttributesHandler;
private ComputedAttributesHandler computedAttributesHandler;
@@ -78,8 +78,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
timeout = Context.getConfig().getInteger(Keys.SERVER_TIMEOUT);
}
- motionHandler = new MotionHandler(Context.getTripsConfig().getSpeedThreshold());
-
if (Context.getConfig().getBoolean("processing.engineHours.enable")) {
engineHoursHandler = new EngineHoursHandler();
}
@@ -165,7 +163,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
pipeline,
Main.getInjector().getInstance(FilterHandler.class),
Main.getInjector().getInstance(GeocoderHandler.class),
- motionHandler,
+ Main.getInjector().getInstance(MotionHandler.class),
engineHoursHandler,
copyAttributesHandler,
computedAttributesHandler);
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index c6ca65088..0c3c5be51 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -47,7 +47,9 @@ import org.traccar.handler.DistanceHandler;
import org.traccar.handler.FilterHandler;
import org.traccar.handler.GeolocationHandler;
import org.traccar.handler.HemisphereHandler;
+import org.traccar.handler.MotionHandler;
import org.traccar.handler.RemoteAddressHandler;
+import org.traccar.reports.model.TripsConfig;
import javax.annotation.Nullable;
import javax.ws.rs.client.Client;
@@ -79,6 +81,11 @@ public class MainModule extends AbstractModule {
return Context.getClient();
}
+ @Provides
+ public static TripsConfig provideTripsConfig() {
+ return Context.getTripsConfig();
+ }
+
@Singleton
@Provides
public static StatisticsManager provideStatisticsManager(Config config, DataManager dataManager, Client client) {
@@ -202,6 +209,12 @@ public class MainModule extends AbstractModule {
return null;
}
+ @Singleton
+ @Provides
+ public static MotionHandler provideMotionHandler(TripsConfig tripsConfig) {
+ return new MotionHandler(tripsConfig.getSpeedThreshold());
+ }
+
@Override
protected void configure() {
binder().requireExplicitBindings();
diff --git a/src/org/traccar/MotionHandler.java b/src/org/traccar/handler/MotionHandler.java
index ec9a5ffd7..e8051dd75 100644
--- a/src/org/traccar/MotionHandler.java
+++ b/src/org/traccar/handler/MotionHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,9 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.traccar;
+package org.traccar.handler;
import io.netty.channel.ChannelHandler;
+import org.traccar.BaseDataHandler;
import org.traccar.model.Position;
@ChannelHandler.Sharable
diff --git a/test/org/traccar/MotionHandlerTest.java b/test/org/traccar/handler/MotionHandlerTest.java
index fc6dce033..9e0859664 100644
--- a/test/org/traccar/MotionHandlerTest.java
+++ b/test/org/traccar/handler/MotionHandlerTest.java
@@ -1,4 +1,4 @@
-package org.traccar;
+package org.traccar.handler;
import static org.junit.Assert.assertEquals;
@@ -8,7 +8,7 @@ import org.traccar.model.Position;
public class MotionHandlerTest {
@Test
- public void testCalculateMotion() throws Exception {
+ public void testCalculateMotion() {
MotionHandler motionHandler = new MotionHandler(0.01);