From 61c54f16cf75d33923fc18b6abcee843f523dec2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 1 Aug 2015 12:01:40 +1200 Subject: Remove disconnected devices from active --- src/org/traccar/MainEventHandler.java | 2 ++ src/org/traccar/database/ConnectionManager.java | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'src/org/traccar') 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); -- cgit v1.2.3