Пример #1
0
 private ChatCache() {
   // singleton
   Map<ChatRoom, SortedMap<Date, ChatMessage>> chatCache = SynchroCache.get("ChatCache");
   if (chatCache == null) {
     chatCache = Maps.newHashMap();
   }
   init(chatCache);
 }
Пример #2
0
 public void recordAndUpdateNewMessage(final ChatMessage aMsg) {
   final SortedMap<Date, ChatMessage> map = getMapForRoom(aMsg.getRoom());
   synchronized (map) {
     if (!map.isEmpty()) {
       final ChatMessage lastMsg = map.get(map.lastKey());
       while (aMsg.getDate().compareTo(lastMsg.getDate()) <= 0) {
         aMsg.setDate(new Date(1 + aMsg.getDate().getTime()));
       }
       aMsg.setPreviousMessageDate(lastMsg.getDate());
     }
     map.put(aMsg.getDate(), aMsg);
     while (map.size() > MAX_ROOM_HIST) {
       map.remove(map.firstKey());
     }
   }
   SynchroCache.put("ChatCache", m_chatCache);
 }