From bf3db6b69ebe36038232fee0de93f7cfbfea45a1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 12 Jan 2017 03:06:42 +1300 Subject: Config option for non-persistent protocols (fix #2100) --- src/org/traccar/CopyAttributesHandler.java | 2 +- src/org/traccar/MainEventHandler.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/org/traccar/CopyAttributesHandler.java b/src/org/traccar/CopyAttributesHandler.java index f6326ea84..18052d0ea 100644 --- a/src/org/traccar/CopyAttributesHandler.java +++ b/src/org/traccar/CopyAttributesHandler.java @@ -33,7 +33,7 @@ public class CopyAttributesHandler extends BaseDataHandler { position.getDeviceId(), "processing.copyAttributes", null, true); Position last = getLastPosition(position.getDeviceId()); if (attributesString != null && last != null) { - for (String attribute : attributesString.split(" ")) { + for (String attribute : attributesString.split("[ ,]")) { if (last.getAttributes().containsKey(attribute) && !position.getAttributes().containsKey(attribute)) { position.getAttributes().put(attribute, last.getAttributes().get(attribute)); } diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index ec31c5efd..b67d7af84 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -29,9 +29,21 @@ import org.traccar.protocol.TeltonikaProtocolDecoder; import java.sql.SQLException; import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class MainEventHandler extends IdleStateAwareChannelHandler { + private final Set connectionlessProtocols = new HashSet<>(); + + public MainEventHandler() { + String connectionlessProtocolList = Context.getConfig().getString("status.ignoreOffline"); + if (connectionlessProtocolList != null) { + connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split(","))); + } + } + @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { @@ -80,8 +92,9 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { Log.info(formatChannel(e.getChannel()) + " disconnected"); closeChannel(e.getChannel()); - if (ctx.getPipeline().get("httpDecoder") == null - && !(ctx.getPipeline().get("objectDecoder") instanceof TeltonikaProtocolDecoder)) { + BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) ctx.getPipeline().get("objectDecoder"); + if (ctx.getPipeline().get("httpDecoder") == null && + !connectionlessProtocols.contains(protocolDecoder.getProtocolName())) { Context.getConnectionManager().removeActiveDevice(e.getChannel()); } } @@ -103,4 +116,5 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { channel.close(); } } + } -- cgit v1.2.3