diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/MainEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/database/ConnectionManager.java | 9 |
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); |