diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 16:16:00 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-09 16:16:00 -0800 |
commit | 2a584c67a1663897d98e7c64fe161c88b30ef314 (patch) | |
tree | 008920bb182dc6ff622c88342b6fa9ca2a998335 /src/org/traccar/handler | |
parent | addbd4b58d959a7996af7631dd3449ac779b027f (diff) | |
download | trackermap-server-2a584c67a1663897d98e7c64fe161c88b30ef314.tar.gz trackermap-server-2a584c67a1663897d98e7c64fe161c88b30ef314.tar.bz2 trackermap-server-2a584c67a1663897d98e7c64fe161c88b30ef314.zip |
Refactor alert event handler
Diffstat (limited to 'src/org/traccar/handler')
-rw-r--r-- | src/org/traccar/handler/events/AlertEventHandler.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/org/traccar/handler/events/AlertEventHandler.java b/src/org/traccar/handler/events/AlertEventHandler.java index 09a6e2b6b..0b7c8d23e 100644 --- a/src/org/traccar/handler/events/AlertEventHandler.java +++ b/src/org/traccar/handler/events/AlertEventHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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. @@ -19,17 +19,21 @@ import java.util.Collections; import java.util.Map; import io.netty.channel.ChannelHandler; -import org.traccar.Context; +import org.traccar.config.Config; +import org.traccar.config.Keys; +import org.traccar.database.IdentityManager; import org.traccar.model.Event; import org.traccar.model.Position; @ChannelHandler.Sharable public class AlertEventHandler extends BaseEventHandler { + private final IdentityManager identityManager; private final boolean ignoreDuplicateAlerts; - public AlertEventHandler() { - ignoreDuplicateAlerts = Context.getConfig().getBoolean("event.ignoreDuplicateAlerts"); + public AlertEventHandler(Config config, IdentityManager identityManager) { + this.identityManager = identityManager; + ignoreDuplicateAlerts = config.getBoolean(Keys.EVENT_IGNORE_DUPLICATE_ALERTS); } @Override @@ -38,7 +42,7 @@ public class AlertEventHandler extends BaseEventHandler { if (alarm != null) { boolean ignoreAlert = false; if (ignoreDuplicateAlerts) { - Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); + Position lastPosition = identityManager.getLastPosition(position.getDeviceId()); if (lastPosition != null && alarm.equals(lastPosition.getAttributes().get(Position.KEY_ALARM))) { ignoreAlert = true; } |