aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 20:02:51 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-09 20:02:51 -0800
commit69ebfe201e6399340545e167110e87fdd4e16a6b (patch)
tree435cf0e2fb2b3858bdbf7360d75afe2c66f3145d /src/org/traccar
parentc7e9f996ed7d183442a7dd2fbbc5c9329981f261 (diff)
downloadtrackermap-server-69ebfe201e6399340545e167110e87fdd4e16a6b.tar.gz
trackermap-server-69ebfe201e6399340545e167110e87fdd4e16a6b.tar.bz2
trackermap-server-69ebfe201e6399340545e167110e87fdd4e16a6b.zip
Refactor driver event handler
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BasePipelineFactory.java8
-rw-r--r--src/org/traccar/MainModule.java7
-rw-r--r--src/org/traccar/handler/events/DriverEventHandler.java14
3 files changed, 18 insertions, 11 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 57e7322aa..f8800ada2 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -59,8 +59,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
private boolean eventsEnabled;
private int timeout;
- private DriverEventHandler driverEventHandler;
-
public BasePipelineFactory(TrackerServer server, String protocol) {
this.server = server;
eventsEnabled = Context.getConfig().getBoolean(Keys.EVENT_ENABLE);
@@ -68,10 +66,6 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
if (timeout == 0) {
timeout = Context.getConfig().getInteger(Keys.SERVER_TIMEOUT);
}
-
- if (eventsEnabled) {
- driverEventHandler = new DriverEventHandler();
- }
}
protected abstract void addProtocolHandlers(PipelineBuilder pipeline);
@@ -152,7 +146,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
Main.getInjector().getInstance(AlertEventHandler.class),
Main.getInjector().getInstance(IgnitionEventHandler.class),
Main.getInjector().getInstance(MaintenanceEventHandler.class),
- driverEventHandler);
+ Main.getInjector().getInstance(DriverEventHandler.class));
}
pipeline.addLast(new MainEventHandler());
diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java
index b459d824d..6fe8bad1c 100644
--- a/src/org/traccar/MainModule.java
+++ b/src/org/traccar/MainModule.java
@@ -61,6 +61,7 @@ import org.traccar.handler.MotionHandler;
import org.traccar.handler.RemoteAddressHandler;
import org.traccar.handler.events.AlertEventHandler;
import org.traccar.handler.events.CommandResultEventHandler;
+import org.traccar.handler.events.DriverEventHandler;
import org.traccar.handler.events.FuelDropEventHandler;
import org.traccar.handler.events.GeofenceEventHandler;
import org.traccar.handler.events.IgnitionEventHandler;
@@ -358,6 +359,12 @@ public class MainModule extends AbstractModule {
return new MaintenanceEventHandler(identityManager, maintenancesManager);
}
+ @Singleton
+ @Provides
+ public static DriverEventHandler provideDriverEventHandler(IdentityManager identityManager) {
+ return new DriverEventHandler(identityManager);
+ }
+
@Override
protected void configure() {
binder().requireExplicitBindings();
diff --git a/src/org/traccar/handler/events/DriverEventHandler.java b/src/org/traccar/handler/events/DriverEventHandler.java
index dbb980c89..994df93fa 100644
--- a/src/org/traccar/handler/events/DriverEventHandler.java
+++ b/src/org/traccar/handler/events/DriverEventHandler.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");
@@ -20,22 +20,28 @@ import java.util.Collections;
import java.util.Map;
import io.netty.channel.ChannelHandler;
-import org.traccar.Context;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Event;
import org.traccar.model.Position;
@ChannelHandler.Sharable
public class DriverEventHandler extends BaseEventHandler {
+ private final IdentityManager identityManager;
+
+ public DriverEventHandler(IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ }
+
@Override
protected Map<Event, Position> analyzePosition(Position position) {
- if (!Context.getIdentityManager().isLatestPosition(position)) {
+ if (!identityManager.isLatestPosition(position)) {
return null;
}
String driverUniqueId = position.getString(Position.KEY_DRIVER_UNIQUE_ID);
if (driverUniqueId != null) {
String oldDriverUniqueId = null;
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ Position lastPosition = identityManager.getLastPosition(position.getDeviceId());
if (lastPosition != null) {
oldDriverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
}