aboutsummaryrefslogtreecommitdiff
path: root/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2011-05-05 06:28:25 +0000
committerAnton Tananaev <anton.tananaev@gmail.com>2011-05-05 06:28:25 +0000
commitd673fa357b64ffa34209465a535d00983cba5576 (patch)
treebff99c61fdf368a915adb336f1d1b173d99b6197 /src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
parentdd6db81db43f5c23e5349c0b06d4a0ce6830d127 (diff)
downloadtrackermap-server-d673fa357b64ffa34209465a535d00983cba5576.tar.gz
trackermap-server-d673fa357b64ffa34209465a535d00983cba5576.tar.bz2
trackermap-server-d673fa357b64ffa34209465a535d00983cba5576.zip
Diffstat (limited to 'src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java')
-rw-r--r--src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
index 7b21a1a72..94b1cb31b 100644
--- a/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
@@ -20,13 +20,17 @@ import java.util.GregorianCalendar;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.text.ParseException;
+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.ChannelPipelineCoverage;
import net.sourceforge.opentracking.Position;
import net.sourceforge.opentracking.DataManager;
-import java.sql.SQLException;
+import org.jboss.netty.channel.ChannelEvent;
+import org.jboss.netty.channel.ChannelState;
+import org.jboss.netty.channel.ChannelStateEvent;
/**
* Xexun tracker protocol decoder
@@ -40,10 +44,16 @@ public class XexunProtocolDecoder extends OneToOneDecoder {
private DataManager dataManager;
/**
+ * Reset connection delay
+ */
+ private Integer resetDelay;
+
+ /**
* Init device table
*/
- public XexunProtocolDecoder(DataManager newDataManager) {
- dataManager = newDataManager;
+ public XexunProtocolDecoder(DataManager dataManager, Integer resetDelay) {
+ this.dataManager = dataManager;
+ this.resetDelay = resetDelay;
}
/**
@@ -129,4 +139,35 @@ public class XexunProtocolDecoder 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);
+ }
+ }
+ }
+
}