/** * 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); }
/** * Returns how often the connection to the given address failed. * * @param address the address * @return number of connection failures */ private static int getConnectionFailures(String address) { Integer count = ADDRESS_BLACKLIST.lookup(address); return count != null ? count : 0; }
/** * Increments the connection failure counter by one for the given address. * * @param address the address the connection failure counter should be increased */ private static void incrementConnectionFailures(String address) { Integer count = ADDRESS_BLACKLIST.lookup(address); ADDRESS_BLACKLIST.put(address, count == null ? 1 : count + 1); }
/** * 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; }
@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); } } });
public static NodeVerHash getNodeVerHashByJid(Jid jid) { return JID_TO_NODEVER_CACHE.lookup(jid); }
/** * 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); }
/** * 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); }
/** * 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; } }
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)); }
@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); }
/** * 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 Map<Resourcepart, Presence> getPresencesInternal(BareJid entity) { Map<Resourcepart, Presence> entityPresences = presenceMap.get(entity); if (entityPresences == null) { entityPresences = nonRosterPresenceMap.lookup(entity); } return entityPresences; }
public void sendFriendshipRequest(BareJid bareJid) throws NotConnectedException, InterruptedException { Presence presence = new Presence(Presence.Type.subscribe); presence.setTo(bareJid); friendshipRequestedCache.put(bareJid, null); connection().sendStanza(presence); }
private static void dropCapsCache() { EntityCapsManager.CAPS_CACHE.clear(); } }
@Override public void presenceSubscribed(BareJid address, Presence subscribedPresence) { friendshipRequestedCache.remove(address); for (BecameFriendListener becameFriendListener : becameFriendListeners) { becameFriendListener.becameFriend(address, subscribedPresence); } } @Override
/** * Get the discover info given a user name. The discover info is returned if * the user has a node#ver associated with it and the node#ver has a * discover info associated with it. * * @param user * user name (Full JID) * @return the discovered info */ public static DiscoverInfo getDiscoverInfoByUser(Jid user) { NodeVerHash nvh = JID_TO_NODEVER_CACHE.lookup(user); if (nvh == null) return null; return getDiscoveryInfoByNodeVer(nvh.nodeVer); }