Commit 62f63dca authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed concurrency problem.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9070 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8b4a6687
...@@ -32,6 +32,7 @@ import org.jivesoftware.openfire.user.UserNotFoundException; ...@@ -32,6 +32,7 @@ import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import org.jivesoftware.util.lock.LockManager;
import org.jivesoftware.util.cache.Cache; import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheFactory; import org.jivesoftware.util.cache.CacheFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -44,6 +45,7 @@ import java.util.ArrayList; ...@@ -44,6 +45,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.locks.Lock;
/** /**
* Simple in memory implementation of the PresenceManager interface. * Simple in memory implementation of the PresenceManager interface.
...@@ -501,23 +503,27 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -501,23 +503,27 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
Lock lock = LockManager.getLock(username + "pr");
try { try {
con = DbConnectionManager.getConnection(); lock.lock();
pstmt = con.prepareStatement(LOAD_OFFLINE_PRESENCE); if (!offlinePresenceCache.containsKey(username) || !lastActivityCache.containsKey(username)) {
pstmt.setString(1, username); con = DbConnectionManager.getConnection();
rs = pstmt.executeQuery(); pstmt = con.prepareStatement(LOAD_OFFLINE_PRESENCE);
if (rs.next()) { pstmt.setString(1, username);
String offlinePresence = DbConnectionManager.getLargeTextField(rs, 1); rs = pstmt.executeQuery();
if (rs.wasNull()) { if (rs.next()) {
offlinePresence = NULL_STRING; String offlinePresence = DbConnectionManager.getLargeTextField(rs, 1);
if (rs.wasNull()) {
offlinePresence = NULL_STRING;
}
long offlineDate = Long.parseLong(rs.getString(2).trim());
offlinePresenceCache.put(username, offlinePresence);
lastActivityCache.put(username, offlineDate);
}
else {
offlinePresenceCache.put(username, NULL_STRING);
lastActivityCache.put(username, NULL_LONG);
} }
long offlineDate = Long.parseLong(rs.getString(2).trim());
offlinePresenceCache.put(username, offlinePresence);
lastActivityCache.put(username, offlineDate);
}
else {
offlinePresenceCache.put(username, NULL_STRING);
lastActivityCache.put(username, NULL_LONG);
} }
} }
catch (SQLException sqle) { catch (SQLException sqle) {
...@@ -525,6 +531,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -525,6 +531,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
} }
finally { finally {
DbConnectionManager.closeConnection(rs, pstmt, con); DbConnectionManager.closeConnection(rs, pstmt, con);
lock.unlock();
} }
} }
} }
\ No newline at end of file
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