mirror of
https://github.com/traccar/traccar.git
synced 2026-04-18 22:27:24 -04:00
Refactor driver event handler
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user