public ConnectedUser findUserByChan(Channel chan) { for (ConnectedUser user : this.connectedUsers) { InetSocketAddress argChanAddr = ((InetSocketAddress) chan.remoteAddress()); InetSocketAddress searchChanAddr = ((InetSocketAddress) user.getChannel().remoteAddress()); if (searchChanAddr.getAddress().equals(argChanAddr.getAddress()) && searchChanAddr.getPort() == argChanAddr.getPort()) { return user; } } return null; }
// TODO timeout handling improvement. use nettys build in handlers which // also take sent traffic into account @Override public void run(Timeout timeout) throws Exception { ArrayList<ConnectedUser> timedOuts = new ArrayList<ConnectedUser>(); MessageProxyServer.this.timeoutChecker.newTimeout( new TimeoutTimerTask(), MessageProxyServer.this.timeoutInSeconds, TimeUnit.SECONDS); for (ConnectedUser user : MessageProxyServer.this.connectedUsers) { if (!user.isAlive()) { timedOuts.add(user); } user.setAlive(false); } for (ConnectedUser user : timedOuts) { clientTimedOut(user.getChannel()); } broadcastMessage(new Message(OpCode.STC_HEARTBEAT_REQUEST)); }