Commit 47cebc50 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed caching problem when deleting a user. JM-642

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3765 b35dd754-fafc-0310-a699-88a17e54d16e
parent 76201a8e
...@@ -41,15 +41,15 @@ public class UserManager implements IQResultListener { ...@@ -41,15 +41,15 @@ public class UserManager implements IQResultListener {
/** /**
* Cache if a local or remote user exists. * Cache if a local or remote user exists.
*/ */
private static Cache<String, Boolean> registeredUsersCache; private static Cache<String, Boolean> remoteUsersCache;
private static UserProvider provider; private static UserProvider provider;
private static UserManager instance = new UserManager(); private static UserManager instance = new UserManager();
static { static {
// Initialize caches. // Initialize caches.
userCache = CacheManager.initializeCache("User", "userCache", 512 * 1024); userCache = CacheManager.initializeCache("User", "userCache", 512 * 1024);
registeredUsersCache = remoteUsersCache =
CacheManager.initializeCache("Users Existence", "registeredUsersCache", 512 * 1024); CacheManager.initializeCache("Remote Users Existence", "remoteUsersCache", 512 * 1024);
CacheManager.initializeCache("Roster", "username2roster", 512 * 1024); CacheManager.initializeCache("Roster", "username2roster", 512 * 1024);
// Load a user provider. // Load a user provider.
String className = JiveGlobals.getXMLProperty("provider.user.className", String className = JiveGlobals.getXMLProperty("provider.user.className",
...@@ -290,21 +290,13 @@ public class UserManager implements IQResultListener { ...@@ -290,21 +290,13 @@ public class UserManager implements IQResultListener {
if (username == null || "".equals(username)) { if (username == null || "".equals(username)) {
return false; return false;
} }
// Look up in the cache
Boolean isRegistered = registeredUsersCache.get(username);
if (isRegistered == null) {
// No information is cached so check user identity and cache it
try { try {
getUser(username); getUser(username);
isRegistered = Boolean.TRUE; return true;
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
isRegistered = Boolean.FALSE; return false;
}
// Cache "discovered" information
registeredUsersCache.put(username, isRegistered);
} }
return isRegistered;
} }
/** /**
...@@ -316,35 +308,24 @@ public class UserManager implements IQResultListener { ...@@ -316,35 +308,24 @@ public class UserManager implements IQResultListener {
* @return true if the specified JID belongs to a local or remote registered user. * @return true if the specified JID belongs to a local or remote registered user.
*/ */
public boolean isRegisteredUser(JID user) { public boolean isRegisteredUser(JID user) {
Boolean isRegistered;
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
if (server.isLocal(user)) { if (server.isLocal(user)) {
isRegistered = registeredUsersCache.get(user.getNode());
}
else {
// Look up in the cache using the full JID
isRegistered = registeredUsersCache.get(user.toString());
if (isRegistered == null) {
// Check if the bare JID of the user is cached
isRegistered = registeredUsersCache.get(user.toBareJID());
}
}
if (isRegistered == null) {
// No information is cached so check user identity and cache it
if (server.isLocal(user)) {
// User belongs to local user so no disco is used in this case
try { try {
getUser(user.getNode()); getUser(user.getNode());
isRegistered = Boolean.TRUE; return true;
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
isRegistered = Boolean.FALSE; return false;
} }
// Cache "discovered" information
registeredUsersCache.put(user.getNode(), isRegistered);
} }
else { else {
// Look up in the cache using the full JID
Boolean isRegistered = remoteUsersCache.get(user.toString());
if (isRegistered == null) {
// Check if the bare JID of the user is cached
isRegistered = remoteUsersCache.get(user.toBareJID());
if (isRegistered == null) {
// No information is cached so check user identity and cache it
// A disco#info is going to be sent to the bare JID of the user. This packet // A disco#info is going to be sent to the bare JID of the user. This packet
// is going to be handled by the remote server. // is going to be handled by the remote server.
IQ iq = new IQ(IQ.Type.get); IQ iq = new IQ(IQ.Type.get);
...@@ -365,17 +346,18 @@ public class UserManager implements IQResultListener { ...@@ -365,17 +346,18 @@ public class UserManager implements IQResultListener {
} }
} }
// Get the discovered result // Get the discovered result
isRegistered = registeredUsersCache.get(user.toBareJID()); isRegistered = remoteUsersCache.get(user.toBareJID());
if (isRegistered == null) { if (isRegistered == null) {
// Disco failed for some reason (i.e. we timed out before getting a result) // Disco failed for some reason (i.e. we timed out before getting a result)
// so assume that user is not anonymous and cache result // so assume that user is not anonymous and cache result
isRegistered = Boolean.FALSE; isRegistered = Boolean.FALSE;
registeredUsersCache.put(user.toString(), isRegistered); remoteUsersCache.put(user.toString(), isRegistered);
} }
} }
} }
return isRegistered; return isRegistered;
} }
}
public void receivedAnswer(IQ packet) { public void receivedAnswer(IQ packet) {
JID from = packet.getFrom(); JID from = packet.getFrom();
...@@ -394,7 +376,7 @@ public class UserManager implements IQResultListener { ...@@ -394,7 +376,7 @@ public class UserManager implements IQResultListener {
} }
} }
// Update cache of remote registered users // Update cache of remote registered users
registeredUsersCache.put(from.toBareJID(), isRegistered); remoteUsersCache.put(from.toBareJID(), isRegistered);
// Wake up waiting thread // Wake up waiting thread
synchronized (from.toBareJID().intern()) { synchronized (from.toBareJID().intern()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment