public void entriesUpdated(Collection<String> updatedIds) {
   try {
     synchronized (XMPPFriendConnectionImpl.this) {
       checkLoggedIn();
       synchronized (friends) {
         Roster roster = connection.getRoster();
         if (roster != null) {
           List<Friend> updatedFriends = new ArrayList<Friend>();
           for (String id : updatedIds) {
             RosterEntry rosterEntry = roster.getEntry(id);
             XMPPFriendImpl friend = friends.get(id);
             if (friend == null) {
               // should never happen ?
               friend =
                   new XMPPFriendImpl(
                       id, rosterEntry, configuration, connection, featureRegistry);
               friends.put(id, friend);
             } else {
               friend.setRosterEntry(rosterEntry);
             }
             updatedFriends.add(friend);
             LOG.debugf("user {0} updated", friend);
           }
           rosterListeners.broadcast(
               new RosterEvent(updatedFriends, RosterEvent.Type.FRIENDS_UPDATED));
         }
       }
     }
   } catch (org.jivesoftware.smack.XMPPException e) {
     LOG.debugf(e, "error getting roster");
   } catch (FriendException e) {
     LOG.debugf(e, "error getting roster");
   }
 }
 public void entriesAdded(Collection<String> addedIds) {
   try {
     synchronized (XMPPFriendConnectionImpl.this) {
       checkLoggedIn();
       synchronized (friends) {
         Roster roster = connection.getRoster();
         if (roster != null) {
           Map<String, XMPPFriendImpl> newFriends = new HashMap<String, XMPPFriendImpl>();
           for (String id : addedIds) {
             RosterEntry rosterEntry = roster.getEntry(id);
             XMPPFriendImpl friend =
                 new XMPPFriendImpl(id, rosterEntry, configuration, connection, featureRegistry);
             LOG.debugf("user {0} added", friend);
             newFriends.put(id, friend);
           }
           friends.putAll(newFriends);
           rosterListeners.broadcast(
               new RosterEvent(
                   new ArrayList<Friend>(newFriends.values()), RosterEvent.Type.FRIENDS_ADDED));
         }
       }
     }
   } catch (org.jivesoftware.smack.XMPPException e) {
     LOG.debugf(e, "error getting roster");
   } catch (FriendException e) {
     LOG.debugf(e, "error getting roster");
   }
 }
 @Override
 public void handleEvent(XmppActivityEvent event) {
   switch (event.getSource()) {
     case Idle:
       try {
         setModeImpl(FriendPresence.Mode.xa);
       } catch (FriendException e) {
         LOG.debugf(e, "couldn't set mode based on {0}", event);
       }
       break;
     case Active:
       try {
         setModeImpl(
             jabberSettings.isDoNotDisturbSet()
                 ? FriendPresence.Mode.dnd
                 : FriendPresence.Mode.available);
       } catch (FriendException e) {
         LOG.debugf(e, "couldn't set mode based on {0}", event);
       }
   }
 }
 public void entriesDeleted(Collection<String> removedIds) {
   synchronized (friends) {
     List<Friend> deletedFriends = new ArrayList<Friend>();
     for (String id : removedIds) {
       XMPPFriendImpl friend = friends.remove(id);
       if (friend != null) {
         deletedFriends.add(friend);
         LOG.debugf("user {0} removed", friend);
       }
     }
     rosterListeners.broadcast(
         new RosterEvent(deletedFriends, RosterEvent.Type.FRIENDS_DELETED));
   }
 }
 @Override
 public void presenceChanged(final org.jivesoftware.smack.packet.Presence presence) {
   String localJID;
   try {
     localJID = getLocalJid();
   } catch (FriendException e) {
     localJID = null;
   }
   if (!presence.getFrom().equals(localJID)) {
     XMPPFriendImpl friend = getFriend(presence);
     if (friend != null) {
       LOG.debugf("presence from {0} changed to {1}", presence.getFrom(), presence.getType());
       // synchronize to avoid updates or presences from being lost
       // better to replace that with a lock object private to this
       // connection class
       synchronized (friend) {
         if (presence.getType().equals(org.jivesoftware.smack.packet.Presence.Type.available)) {
           if (!friend.getPresences().containsKey(presence.getFrom())) {
             addNewPresence(friend, presence);
           } else {
             updatePresence(friend, presence);
           }
         } else if (presence
             .getType()
             .equals(org.jivesoftware.smack.packet.Presence.Type.unavailable)) {
           PresenceImpl p = (PresenceImpl) friend.getPresence(presence.getFrom());
           if (p != null) {
             p.update(presence);
             friend.removePresense(p);
           }
         }
       }
     } else {
       LOG.debugf("no friend for presence {0}", presence.getFrom());
     }
   }
 }