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 try {
Boolean isRegistered = registeredUsersCache.get(username); getUser(username);
if (isRegistered == null) { return true;
// No information is cached so check user identity and cache it }
try { catch (UserNotFoundException e) {
getUser(username); return false;
isRegistered = Boolean.TRUE;
}
catch (UserNotFoundException e) {
isRegistered = Boolean.FALSE;
}
// Cache "discovered" information
registeredUsersCache.put(username, isRegistered);
} }
return isRegistered;
} }
/** /**
...@@ -316,65 +308,55 @@ public class UserManager implements IQResultListener { ...@@ -316,65 +308,55 @@ 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()); try {
getUser(user.getNode());
return true;
}
catch (UserNotFoundException e) {
return false;
}
} }
else { else {
// Look up in the cache using the full JID // Look up in the cache using the full JID
isRegistered = registeredUsersCache.get(user.toString()); Boolean isRegistered = remoteUsersCache.get(user.toString());
if (isRegistered == null) { if (isRegistered == null) {
// Check if the bare JID of the user is cached // Check if the bare JID of the user is cached
isRegistered = registeredUsersCache.get(user.toBareJID()); 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
if (isRegistered == null) { // is going to be handled by the remote server.
// No information is cached so check user identity and cache it IQ iq = new IQ(IQ.Type.get);
if (server.isLocal(user)) { iq.setFrom(server.getServerInfo().getName());
// User belongs to local user so no disco is used in this case iq.setTo(user.toBareJID());
try { iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
getUser(user.getNode()); // Send the disco#info request to the remote server. The reply will be
isRegistered = Boolean.TRUE; // processed by the IQResultListener (interface that this class implements)
} server.getIQRouter().addIQResultListener(iq.getID(), this);
catch (UserNotFoundException e) { synchronized (user.toBareJID().intern()) {
isRegistered = Boolean.FALSE; server.getIQRouter().route(iq);
} // Wait for the reply to be processed. Time out in 10 minutes.
// Cache "discovered" information try {
registeredUsersCache.put(user.getNode(), isRegistered); user.toBareJID().intern().wait(600000);
} }
else { catch (InterruptedException e) {
// A disco#info is going to be sent to the bare JID of the user. This packet // Do nothing
// is going to be handled by the remote server. }
IQ iq = new IQ(IQ.Type.get);
iq.setFrom(server.getServerInfo().getName());
iq.setTo(user.toBareJID());
iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
// Send the disco#info request to the remote server. The reply will be
// processed by the IQResultListener (interface that this class implements)
server.getIQRouter().addIQResultListener(iq.getID(), this);
synchronized (user.toBareJID().intern()) {
server.getIQRouter().route(iq);
// Wait for the reply to be processed. Time out in 10 minutes.
try {
user.toBareJID().intern().wait(600000);
} }
catch (InterruptedException e) { // Get the discovered result
// Do nothing isRegistered = remoteUsersCache.get(user.toBareJID());
if (isRegistered == null) {
// Disco failed for some reason (i.e. we timed out before getting a result)
// so assume that user is not anonymous and cache result
isRegistered = Boolean.FALSE;
remoteUsersCache.put(user.toString(), isRegistered);
} }
} }
// Get the discovered result
isRegistered = registeredUsersCache.get(user.toBareJID());
if (isRegistered == null) {
// Disco failed for some reason (i.e. we timed out before getting a result)
// so assume that user is not anonymous and cache result
isRegistered = Boolean.FALSE;
registeredUsersCache.put(user.toString(), isRegistered);
}
} }
return isRegistered;
} }
return isRegistered;
} }
public void receivedAnswer(IQ packet) { public void receivedAnswer(IQ packet) {
...@@ -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