diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2012-03-22 04:54:46 +0000 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2012-03-22 04:54:46 +0000 |
commit | d0de5245574e223384d9e89421850af16fb7a848 (patch) | |
tree | 8203e522ecfc6540284ef3c29c9af1c42be5e84a /src/org/traccar | |
parent | 2298302ea7f3b4f09b52638355c2b86a952a8306 (diff) | |
download | trackermap-server-d0de5245574e223384d9e89421850af16fb7a848.tar.gz trackermap-server-d0de5245574e223384d9e89421850af16fb7a848.tar.bz2 trackermap-server-d0de5245574e223384d9e89421850af16fb7a848.zip |
Diffstat (limited to 'src/org/traccar')
10 files changed, 129 insertions, 424 deletions
diff --git a/src/org/traccar/GenericProtocolDecoder.java b/src/org/traccar/GenericProtocolDecoder.java new file mode 100644 index 000000000..0d79818ab --- /dev/null +++ b/src/org/traccar/GenericProtocolDecoder.java @@ -0,0 +1,88 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar; + +import java.util.Timer; +import java.util.TimerTask; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; +import org.jboss.netty.channel.ChannelEvent; +import org.jboss.netty.channel.ChannelState; +import org.jboss.netty.channel.ChannelStateEvent; + +/** + * Base class for protocol decoders + */ +public abstract class GenericProtocolDecoder extends OneToOneDecoder { + + /** + * Data manager + */ + private DataManager dataManager; + + /** + * Return data manager + */ + public DataManager getDataManager() { + return dataManager; + } + + /** + * Reset connection delay + */ + private Integer resetDelay; + + /** + * Initialize variables + */ + public GenericProtocolDecoder(DataManager dataManager, Integer resetDelay) { + this.dataManager = dataManager; + this.resetDelay = resetDelay; + } + + /** + * Disconnect channel + */ + private class DisconnectTask extends TimerTask { + private Channel channel; + + public DisconnectTask(Channel channel) { + this.channel = channel; + } + + public void run() { + channel.disconnect(); + } + } + + /** + * Handle connect event + */ + @Override + public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { + super.handleUpstream(ctx, evt); + + if (evt instanceof ChannelStateEvent) { + ChannelStateEvent event = (ChannelStateEvent) evt; + + if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { + new Timer().schedule(new GenericProtocolDecoder.DisconnectTask(evt.getChannel()), resetDelay); + } + } + } + +} diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 2fa9b8f1d..9f6d326c9 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -646,7 +646,7 @@ public class Server implements DataManager { Integer.valueOf(properties.getProperty("avl08.port"))); String resetDelay = properties.getProperty("avl08.resetDelay"); - server.setPipelineFactory(new Xexun2PipelineFactory( + server.setPipelineFactory(new Avl08PipelineFactory( server, this, (resetDelay == null) ? 0 : Integer.valueOf(resetDelay))); serverList.add(server); diff --git a/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java index ca59b8413..cc8a2efb7 100644 --- a/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java +++ b/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java @@ -15,49 +15,27 @@ */ package org.traccar.protocol.avl08; -import java.text.ParseException; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * AVL-08 tracker protocol decoder */ -public class Avl08ProtocolDecoder extends OneToOneDecoder { +public class Avl08ProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** - * Device ID - */ - private Long deviceId; - - /** - * Init device table + * Initialize */ public Avl08ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -99,7 +77,7 @@ public class Avl08ProtocolDecoder extends OneToOneDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(dataManager.getDeviceByImei(imei).getId()); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Time Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); @@ -147,35 +125,4 @@ public class Avl08ProtocolDecoder extends OneToOneDecoder { return position; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new Avl08ProtocolDecoder.DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } diff --git a/src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java index f762753b4..e4c0de38a 100644 --- a/src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java @@ -18,40 +18,24 @@ package org.traccar.protocol.gl100; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * GL200 tracker protocol decoder */ -public class Gl100ProtocolDecoder extends OneToOneDecoder { +public class Gl100ProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** - * Init device table + * Initialize */ public Gl100ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -105,7 +89,7 @@ public class Gl100ProtocolDecoder extends OneToOneDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(dataManager.getDeviceByImei(imei).getId()); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Validity position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); @@ -133,35 +117,4 @@ public class Gl100ProtocolDecoder extends OneToOneDecoder { return position; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } diff --git a/src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java index 984eb91d8..4c1149347 100644 --- a/src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java @@ -18,40 +18,24 @@ package org.traccar.protocol.gl200; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * GL200 tracker protocol decoder */ -public class Gl200ProtocolDecoder extends OneToOneDecoder { +public class Gl200ProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** - * Init device table + * Initialize */ public Gl200ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -98,7 +82,7 @@ public class Gl200ProtocolDecoder extends OneToOneDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(dataManager.getDeviceByImei(imei).getId()); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Validity position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); @@ -126,35 +110,4 @@ public class Gl200ProtocolDecoder extends OneToOneDecoder { return position; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } diff --git a/src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java index 46a089057..f50dfad2a 100644 --- a/src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java @@ -18,40 +18,24 @@ package org.traccar.protocol.gps103; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * Gps 103 tracker protocol decoder */ -public class Gps103ProtocolDecoder extends OneToOneDecoder { +public class Gps103ProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** - * Init device table + * Initialize */ public Gps103ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -105,7 +89,7 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(dataManager.getDeviceByImei(imei).getId()); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Date Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); @@ -146,35 +130,4 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder { return position; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } diff --git a/src/org/traccar/protocol/t55/T55ProtocolDecoder.java b/src/org/traccar/protocol/t55/T55ProtocolDecoder.java index ad674d4a8..5b1558c00 100644 --- a/src/org/traccar/protocol/t55/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/t55/T55ProtocolDecoder.java @@ -18,45 +18,29 @@ package org.traccar.protocol.t55; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * T55 tracker protocol decoder */ -public class T55ProtocolDecoder extends OneToOneDecoder { +public class T55ProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** * Device ID */ private Long deviceId; /** - * Init device table + * Initialize */ public T55ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -89,7 +73,7 @@ public class T55ProtocolDecoder extends OneToOneDecoder { // Detect device ID if (sentence.contains("$PGID")) { String imei = sentence.substring(6, 6 + 15); - deviceId = dataManager.getDeviceByImei(imei).getId(); + deviceId = getDataManager().getDeviceByImei(imei).getId(); } // Parse message @@ -166,35 +150,4 @@ public class T55ProtocolDecoder extends OneToOneDecoder { return null; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } diff --git a/src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java index bc5685ecd..db3280d91 100644 --- a/src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java @@ -18,40 +18,24 @@ package org.traccar.protocol.tk103; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * Gps 103 tracker protocol decoder */ -public class Tk103ProtocolDecoder extends OneToOneDecoder { +public class Tk103ProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** - * Init device table + * Initialize */ public Tk103ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -99,7 +83,7 @@ public class Tk103ProtocolDecoder extends OneToOneDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(dataManager.getDeviceByImei(imei).getId()); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Date Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); @@ -141,35 +125,4 @@ public class Tk103ProtocolDecoder extends OneToOneDecoder { return position; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } diff --git a/src/org/traccar/protocol/xexun/XexunProtocolDecoder.java b/src/org/traccar/protocol/xexun/XexunProtocolDecoder.java index c73047576..46b88f8a3 100644 --- a/src/org/traccar/protocol/xexun/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/xexun/XexunProtocolDecoder.java @@ -21,38 +21,22 @@ import java.util.regex.Pattern; import java.util.regex.Matcher; import java.text.ParseException; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * Xexun tracker protocol decoder */ -public class XexunProtocolDecoder extends OneToOneDecoder { +public class XexunProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** - * Init device table + * Initialize */ public XexunProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -136,40 +120,9 @@ public class XexunProtocolDecoder extends OneToOneDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(dataManager.getDeviceByImei(imei).getId()); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); return position; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } diff --git a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java index b8ed8a54f..62ec432ee 100644 --- a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java +++ b/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java @@ -19,40 +19,23 @@ import java.util.Calendar; import java.util.GregorianCalendar; import java.util.regex.Pattern; import java.util.regex.Matcher; -import java.text.ParseException; import java.util.TimeZone; -import java.util.Timer; -import java.util.TimerTask; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.Position; import org.traccar.DataManager; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelState; -import org.jboss.netty.channel.ChannelStateEvent; +import org.traccar.GenericProtocolDecoder; /** * Xexun tracker protocol decoder */ -public class Xexun2ProtocolDecoder extends OneToOneDecoder { +public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - - /** - * Init device table + * Initialize */ public Xexun2ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -145,7 +128,7 @@ public class Xexun2ProtocolDecoder extends OneToOneDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(dataManager.getDeviceByImei(imei).getId()); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Power position.setPower(Double.valueOf(parser.group(index++))); @@ -153,35 +136,4 @@ public class Xexun2ProtocolDecoder extends OneToOneDecoder { return position; } - /** - * Disconnect channel - */ - class DisconnectTask extends TimerTask { - private Channel channel; - - public DisconnectTask(Channel channel) { - this.channel = channel; - } - - public void run() { - channel.disconnect(); - } - } - - /** - * Handle connect event - */ - @Override - public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - super.handleUpstream(ctx, evt); - - if (evt instanceof ChannelStateEvent) { - ChannelStateEvent event = (ChannelStateEvent) evt; - - if (event.getState() == ChannelState.CONNECTED && event.getValue() != null && resetDelay != 0) { - new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay); - } - } - } - } |