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();
      }
    }
  }
示例#2
0
 public ListNode deleteDuplicates(ListNode a) {
   ListNode temp = a;
   LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
   int i = 0;
   while (temp != null) {
     if (map.get(temp.val) == null) {
       map.put(temp.val, 1);
     } else {
       map.put(temp.val, map.get(temp.val) + 1);
     }
     temp = temp.next;
   }
   System.out.println(map);
   Iterator<Integer> it = map.keySet().iterator();
   ListNode root = null;
   ListNode root1 = null;
   while (it.hasNext()) {
     int x = it.next();
     if (map.get(x) == 1) {
       if (root == null) {
         root = new ListNode(x);
         root1 = root;
       } else {
         ListNode node = new ListNode(x);
         root1.next = node;
         root1 = node;
       }
     }
   }
   return root;
 }
 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;
 }
 private void updateChannelsCache() {
   channelsCache = (LinkedHashMap) channels.clone();
 }
 public Iterable<? extends IChannelInfo> getChannels() {
   return channelsCache.values();
 }