diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 17:09:13 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 17:09:13 -0800 |
commit | 312f5d2a3af3ec53cc6ff73cd3424d68a2774dcd (patch) | |
tree | e87286756e9a58144085815b70a226be755f3dbd /src/org | |
parent | 5c084a0b2961dbfc3cd85a386fefe0b0da6c0c44 (diff) | |
download | trackermap-server-312f5d2a3af3ec53cc6ff73cd3424d68a2774dcd.tar.gz trackermap-server-312f5d2a3af3ec53cc6ff73cd3424d68a2774dcd.tar.bz2 trackermap-server-312f5d2a3af3ec53cc6ff73cd3424d68a2774dcd.zip |
Refactor default data handler
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 8 | ||||
-rw-r--r-- | src/org/traccar/MainModule.java | 10 | ||||
-rw-r--r-- | src/org/traccar/handler/DefaultDataHandler.java (renamed from src/org/traccar/DefaultDataHandler.java) | 16 |
3 files changed, 26 insertions, 8 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 550145860..e3328a524 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -25,6 +25,7 @@ import io.netty.handler.timeout.IdleStateHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.config.Keys; +import org.traccar.handler.DefaultDataHandler; import org.traccar.handler.events.AlertEventHandler; import org.traccar.handler.events.CommandResultEventHandler; import org.traccar.handler.events.DriverEventHandler; @@ -139,11 +140,8 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { Main.getInjector().getInstance(EngineHoursHandler.class), Main.getInjector().getInstance(CopyAttributesHandler.class), Main.getInjector().getInstance(ComputedAttributesHandler.class), - Main.getInjector().getInstance(WebDataHandler.class)); - - if (Context.getDataManager() != null) { - pipeline.addLast(new DefaultDataHandler()); - } + Main.getInjector().getInstance(WebDataHandler.class), + Main.getInjector().getInstance(DefaultDataHandler.class)); if (eventsEnabled) { addHandlers( diff --git a/src/org/traccar/MainModule.java b/src/org/traccar/MainModule.java index 8ad89529f..16a78b109 100644 --- a/src/org/traccar/MainModule.java +++ b/src/org/traccar/MainModule.java @@ -49,6 +49,7 @@ import org.traccar.geolocation.OpenCellIdGeolocationProvider; import org.traccar.geolocation.UnwiredGeolocationProvider; import org.traccar.handler.ComputedAttributesHandler; import org.traccar.handler.CopyAttributesHandler; +import org.traccar.handler.DefaultDataHandler; import org.traccar.handler.DistanceHandler; import org.traccar.handler.EngineHoursHandler; import org.traccar.handler.FilterHandler; @@ -291,6 +292,15 @@ public class MainModule extends AbstractModule { @Singleton @Provides + public static DefaultDataHandler provideDefaultDataHandler(@Nullable DataManager dataManager) { + if (dataManager != null) { + return new DefaultDataHandler(dataManager); + } + return null; + } + + @Singleton + @Provides public static CommandResultEventHandler provideCommandResultEventHandler() { return new CommandResultEventHandler(); } diff --git a/src/org/traccar/DefaultDataHandler.java b/src/org/traccar/handler/DefaultDataHandler.java index 876ecd90e..9d8ea044d 100644 --- a/src/org/traccar/DefaultDataHandler.java +++ b/src/org/traccar/handler/DefaultDataHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2019 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. @@ -13,21 +13,31 @@ * 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.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.traccar.BaseDataHandler; +import org.traccar.database.DataManager; import org.traccar.model.Position; +@ChannelHandler.Sharable public class DefaultDataHandler extends BaseDataHandler { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataHandler.class); + private final DataManager dataManager; + + public DefaultDataHandler(DataManager dataManager) { + this.dataManager = dataManager; + } + @Override protected Position handlePosition(Position position) { try { - Context.getDataManager().addObject(position); + dataManager.addObject(position); } catch (Exception error) { LOGGER.warn("Failed to store position", error); } |