/** * Retrieve DiscoverInfo for a specific node. * * @param nodeVer * The node name (e.g. * "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w="). * @return The corresponding DiscoverInfo or null if none is known. */ public static DiscoverInfo getDiscoveryInfoByNodeVer(String nodeVer) { DiscoverInfo info = CAPS_CACHE.lookup(nodeVer); // If it was not in CAPS_CACHE, try to retrieve the information from persistentCache if (info == null && persistentCache != null) { info = persistentCache.lookup(nodeVer); // Promote the information to CAPS_CACHE if one was found if (info != null) { CAPS_CACHE.put(nodeVer, info); } } // If we were able to retrieve information from one of the caches, copy it before returning if (info != null) info = new DiscoverInfo(info); return info; }
/** * Retrieve the user presences (a map from resource to {@link Presence}) for a given XMPP entity represented by their bare JID. * * @param entity the entity * @return the user presences */ private synchronized Map<Resourcepart, Presence> getOrCreatePresencesInternal(BareJid entity) { Map<Resourcepart, Presence> entityPresences = getPresencesInternal(entity); if (entityPresences == null) { if (contains(entity)) { entityPresences = new ConcurrentHashMap<>(); presenceMap.put(entity, entityPresences); } else { LruCache<Resourcepart, Presence> nonRosterEntityPresences = new LruCache<>(32); nonRosterPresenceMap.put(entity, nonRosterEntityPresences); entityPresences = nonRosterEntityPresences; } } return entityPresences; }
@Override public IQ handleIQRequest(IQ iqRequest) { if (!isFromProvisioningService(iqRequest, true)) { return null; } ClearCache clearCache = (ClearCache) iqRequest; // Handle <clearCache/> request. Jid from = iqRequest.getFrom(); LruCache<BareJid, Void> cache = negativeFriendshipRequestCache.lookup(from); if (cache != null) { cache.clear(); } return new ClearCacheResponse(clearCache); } });
@Override public void presenceUnsubscribed(BareJid address, Presence unsubscribedPresence) { if (friendshipRequestedCache.containsKey(address)) { friendshipDeniedCache.put(address, null); } for (WasUnfriendedListener wasUnfriendedListener : wasUnfriendedListeners) { wasUnfriendedListener.wasUnfriendedListener(address, unsubscribedPresence); } } });
LruCache<BareJid, Void> cache = negativeFriendshipRequestCache.lookup(provisioningServer); if (cache != null && cache.containsKey(friendInQuestion)) { cache = new LruCache<>(1024); negativeFriendshipRequestCache.put(provisioningServer, cache); cache.put(friendInQuestion, null);
/** * Add DiscoverInfo to the database. * * @param nodeVer * The node and verification String (e.g. * "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w="). * @param info * DiscoverInfo for the specified node. */ static void addDiscoverInfoByNode(String nodeVer, DiscoverInfo info) { CAPS_CACHE.put(nodeVer, info); if (persistentCache != null) persistentCache.addDiscoverInfoByNodePersistent(nodeVer, info); }
public static NodeVerHash getNodeVerHashByJid(Jid jid) { return JID_TO_NODEVER_CACHE.lookup(jid); }
/** * Remove a record telling what entity caps node a user has. * * @param user * the user (Full JID) */ public static void removeUserCapsNode(Jid user) { // While JID_TO_NODEVER_CHACHE has the generic types <Jid, NodeVerHash>, it is ok to call remove with String // arguments, since the same Jid and String representations would be equal and have the same hash code. JID_TO_NODEVER_CACHE.remove(user); }
/** * Sets the maximum cache sizes. * * @param maxJidToNodeVerSize * @param maxCapsCacheSize */ public static void setMaxsCacheSizes(int maxJidToNodeVerSize, int maxCapsCacheSize) { JID_TO_NODEVER_CACHE.setMaxCacheSize(maxJidToNodeVerSize); CAPS_CACHE.setMaxCacheSize(maxCapsCacheSize); }
/** * Construct a new expiration cache. * * @param maxSize the maximum size. * @param defaultExpirationTime the default expiration time in milliseconds. */ public ExpirationCache(int maxSize, long defaultExpirationTime) { cache = new LruCache<K, ExpireElement<V>>(maxSize); setDefaultExpirationTime(defaultExpirationTime); }
if (!friendshipDeniedCache.containsKey(bareFrom)) { LOGGER.log(Level.WARNING, "Ignoring friendship recommendation " + friendMessage
LruCache<BareJid, Void> cache = negativeFriendshipRequestCache.lookup(provisioningServer); if (cache != null && cache.containsKey(friendInQuestion)) { cache = new LruCache<>(1024); negativeFriendshipRequestCache.put(provisioningServer, cache); cache.put(friendInQuestion, null);
private static void addCapsExtensionInfo(Jid from, CapsExtension capsExtension) { String capsExtensionHash = capsExtension.getHash(); String hashInUppercase = capsExtensionHash.toUpperCase(Locale.US); // SUPPORTED_HASHES uses the format of MessageDigest, which is uppercase, e.g. "SHA-1" instead of "sha-1" if (!SUPPORTED_HASHES.containsKey(hashInUppercase)) return; String hash = capsExtensionHash.toLowerCase(Locale.US); String node = capsExtension.getNode(); String ver = capsExtension.getVer(); JID_TO_NODEVER_CACHE.put(from, new NodeVerHash(node, ver, hash)); }
/** * Get the Node version (node#ver) of a JID. Returns a String or null if * EntiyCapsManager does not have any information. * * @param jid * the user (Full JID) * @return the node version (node#ver) or null */ public static String getNodeVersionByJid(Jid jid) { NodeVerHash nvh = JID_TO_NODEVER_CACHE.lookup(jid); if (nvh != null) { return nvh.nodeVer; } else { return null; } }
@Override public void presenceUnsubscribed(BareJid address, Presence unsubscribedPresence) { if (friendshipRequestedCache.containsKey(address)) { friendshipDeniedCache.put(address, null); } for (WasUnfriendedListener wasUnfriendedListener : wasUnfriendedListeners) { wasUnfriendedListener.wasUnfriendedListener(address, unsubscribedPresence); } } });
@Override public void presenceUnavailable(FullJid from, Presence presence) { JID_TO_NODEVER_CACHE.remove(from); } });
/** * Set the maximum size of the non-Roster presence map. * * @param maximumSize * @since 4.2 * @see #setDefaultNonRosterPresenceMapMaxSize(int) */ public void setNonRosterPresenceMapMaxSize(int maximumSize) { nonRosterPresenceMap.setMaxCacheSize(maximumSize); }
public ExpirationCache(int maxSize, long defaultExpirationTime) { cache = new LruCache<K, ExpireElement<V>>(maxSize); setDefaultExpirationTime(defaultExpirationTime); }