@Override
    public void userUnavailable(Presence presence) {
        // Only save the last presence status and keep track of the time when the user went
        // offline if this is an unavailable presence sent to THE SERVER and the presence belongs
        // to a local user.
        if (presence.getTo() == null && userManager.isRegisteredUser(presence.getFrom(), false)) {
            String username = presence.getFrom().getNode();

            // If the user has any remaining sessions, don't record the offline info.
            if (sessionManager.getActiveSessionCount(username) > 0) {
                return;
            }

            String offlinePresence = null;
            // Save the last unavailable presence of this user if the presence contains any
            // child element such as <status>.
            if (!presence.getElement().elements().isEmpty()) {
                offlinePresence = presence.toXML();
            }
            // Keep track of the time when the user went offline
            java.util.Date offlinePresenceDate = new java.util.Date();

            boolean addedToCache;
            if (offlinePresence == null) {
                addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
            }
            else {
                addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
            }
            if (!addedToCache) {
                return;
            }
            Log.debug( "Recording 'last activity' for user '{}'.", username);
            lastActivityCache.put(username, offlinePresenceDate.getTime());

            writeToDatabase(username, offlinePresence, offlinePresenceDate);
        }
    }
Simple in memory implementation of the PresenceManager interface.

@author Iain Shigeoka
xmppserver/src/main/java/org/jivesoftware/openfire/spi/PresenceManagerImpl.java