aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-08-01 12:01:40 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-08-01 12:01:40 +1200
commit61c54f16cf75d33923fc18b6abcee843f523dec2 (patch)
tree9e0b0fc1426ce262942bcd34dfc332777e32e03a /src/org/traccar
parent362fb75ec0ff6f6c615f07abde917cb55da4de5c (diff)
downloadtraccar-server-61c54f16cf75d33923fc18b6abcee843f523dec2.tar.gz
traccar-server-61c54f16cf75d33923fc18b6abcee843f523dec2.tar.bz2
traccar-server-61c54f16cf75d33923fc18b6abcee843f523dec2.zip
Remove disconnected devices from active
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/MainEventHandler.java2
-rw-r--r--src/org/traccar/database/ConnectionManager.java9
2 files changed, 11 insertions, 0 deletions
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
index 034cd4371..9c28d7c9d 100644
--- a/src/org/traccar/MainEventHandler.java
+++ b/src/org/traccar/MainEventHandler.java
@@ -62,6 +62,8 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
Log.info(formatChannel(e.getChannel()) + " disconnected");
e.getChannel().close();
+
+ Context.getConnectionManager().removeActiveDevice(e.getChannel());
}
@Override
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index 39ec465e6..1aa0dbc57 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -50,6 +50,15 @@ public class ConnectionManager {
public void setActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
activeDevices.put(deviceId, new ActiveDevice(deviceId, protocol, channel, remoteAddress));
}
+
+ public void removeActiveDevice(Channel channel) {
+ for (ActiveDevice activeDevice : activeDevices.values()) {
+ if (activeDevice.getChannel() == channel) {
+ activeDevices.remove(activeDevice.getDeviceId());
+ break;
+ }
+ }
+ }
public ActiveDevice getActiveDevice(long deviceId) {
return activeDevices.get(deviceId);