private void stepTimeout() { boolean updated = false; synchronized (channels) { Iterator<ChannelInfo> it = channels.values().iterator(); while (it.hasNext()) { ChannelInfo channel = it.next(); Iterator<UserInfo> removed = channel.stepTimeout(getTimeoutLimit()); if (removed != null) { updated = true; String channelName = channel.getChannelName(); while (removed.hasNext()) { UserInfo user = removed.next(); ServerLogger.getInstance() .channelLeaved(channelName, user.getUserName(), user.getInetSocketAddress()); } if (channel.isEmpty()) { it.remove(); ServerLogger.getInstance().channelRemoved(channelName); } } } if (updated) { updateChannelsCache(); } } }
ShutDownThread(FkServer server, int shutdownPort) throws IOException { super("ShutDownThread"); this.server = server; this.shutdownSocket = new ServerSocket(shutdownPort); this.setDaemon(true); ServerLogger.info(String.format("listening shutdownPort %s", shutdownPort)); }
public void run() { Socket socketForShutdown = null; try { socketForShutdown = shutdownSocket.accept(); BufferedReader br = new BufferedReader(new InputStreamReader(socketForShutdown.getInputStream())); String command = br.readLine(); if (command.equals("shutdown")) { server.shutdown(); } } catch (Exception e) { ServerLogger.error("ShutDownThread error:", e); } try { shutdownSocket.close(); } catch (IOException e) { ServerLogger.error("ShutDownThread error:", e); } }
public IChannelInfo channelData( String channelName, String userName, InetSocketAddress userAddress) { // System.out.println("channelName channel:"+channelName+" user:"******" // addr:"+userAddress); ChannelInfo channel = channelsCache.get(channelName); if (channel == null) { synchronized (channels) { channel = channels.get(channelName); if (channel == null) { channel = new ChannelInfo(channelName); channels.put(channelName, channel); updateChannelsCache(); ServerLogger.getInstance().channelCreated(channelName); } } } boolean updated = channel.userData(userName, userAddress); if (updated) { ServerLogger.getInstance().channelJoined(channelName, userName, userAddress); } return channel; }