Commit 750b4c24 authored by Pete Matern's avatar Pete Matern Committed by pete

Replaces usages of CacheManager.initializeCache with CacheFactory.createCache....

Replaces usages of CacheManager.initializeCache with CacheFactory.createCache. Added coherence config files.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8151 b35dd754-fafc-0310-a699-88a17e54d16e
parent 2c8bf70c
......@@ -13,8 +13,7 @@ package org.jivesoftware.openfire;
import org.dom4j.Element;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
import org.xmpp.packet.IQ;
......@@ -87,8 +86,7 @@ public class MulticastRouter extends BasicModule implements ServerFeaturesProvid
super("Multicast Packet Router");
String cacheName = "Multicast Service";
CacheManager.initializeCache(cacheName, "multicast", 128 * 1024, JiveConstants.DAY);
cache = CacheManager.getCache(cacheName);
cache = CacheFactory.createCache(cacheName);
}
public void route(Packet packet) {
......
......@@ -18,7 +18,7 @@ import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.database.SequenceManager;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.event.UserEventListener;
......@@ -93,8 +93,7 @@ public class OfflineMessageStore extends BasicModule implements UserEventListene
super("Offline Message Store");
dateFormat = FastDateFormat.getInstance(JiveConstants.XMPP_DELAY_DATETIME_FORMAT,
TimeZone.getTimeZone("UTC"));
sizeCache = CacheManager.initializeCache("Offline Message Size", "offlinemessage",
1024 * 100, JiveConstants.HOUR * 12);
sizeCache = CacheFactory.createCache("Offline Message Size");
}
/**
......
......@@ -13,7 +13,7 @@ package org.jivesoftware.openfire.auth;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.user.UserAlreadyExistsException;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
......@@ -79,12 +79,8 @@ public class POP3AuthProvider implements AuthProvider {
*/
public POP3AuthProvider() {
if (Boolean.valueOf(JiveGlobals.getXMLProperty("pop3.authCache.enabled"))) {
int maxSize = JiveGlobals.getXMLProperty("pop3.authCache.size", 512*1024);
long maxLifetime = (long)JiveGlobals.getXMLProperty("pop3.authCache.maxLifetime",
(int)JiveConstants.HOUR);
String cacheName = "POP3 Authentication";
CacheManager.initializeCache(cacheName, "pop3", maxSize, maxLifetime);
authCache = CacheManager.getCache(cacheName);
authCache = CacheFactory.createCache(cacheName);
}
useSSL = Boolean.valueOf(JiveGlobals.getXMLProperty("pop3.ssl"));
......
......@@ -13,6 +13,7 @@ package org.jivesoftware.openfire.filetransfer;
import org.dom4j.Element;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.DefaultCache;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.container.BasicModule;
......@@ -49,19 +50,10 @@ public class DefaultFileTransferManager extends BasicModule implements FileTrans
*/
public DefaultFileTransferManager() {
super("File Transfer Manager");
fileTransferMap = createCache(CACHE_NAME, "fileTransfer", 128 * 1024, 1000 * 60 * 10);
fileTransferMap = CacheFactory.createCache(CACHE_NAME);
InterceptorManager.getInstance().addInterceptor(new MetaFileTransferInterceptor());
}
private Cache<String, FileTransfer> createCache(String name, String propertiesName, int size,
long expirationTime)
{
size = JiveGlobals.getIntProperty("cache." + propertiesName + ".size", size);
expirationTime = (long) JiveGlobals.getIntProperty(
"cache." + propertiesName + ".expirationTime", (int) expirationTime);
return new DefaultCache<String, FileTransfer>(name, size, expirationTime);
}
/**
* Returns true if the proxy transfer should be matched to an existing file transfer
* in the system.
......
......@@ -13,6 +13,7 @@ package org.jivesoftware.openfire.filetransfer.proxy;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.DefaultCache;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.filetransfer.FileTransferManager;
import org.jivesoftware.openfire.filetransfer.FileTransferRejectedException;
......@@ -60,7 +61,7 @@ public class ProxyConnectionManager {
public ProxyConnectionManager(FileTransferManager manager) {
String cacheName = "File Transfer";
connectionMap = new DefaultCache<String, ProxyTransfer>(cacheName, -1, 1000 * 60 * 10);
connectionMap = CacheFactory.createCache(cacheName);
className = JiveGlobals.getProperty("provider.transfer.proxy",
"org.jivesoftware.openfire.filetransfer.proxy.DefaultProxyTransfer");
......
......@@ -11,15 +11,15 @@
package org.jivesoftware.openfire.group;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.event.GroupEventListener;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.xmpp.packet.JID;
import java.util.Collection;
......@@ -55,13 +55,11 @@ public class GroupManager {
private GroupManager() {
// Initialize caches.
groupCache = CacheManager.initializeCache("Group", "group", 1024 * 1024,
JiveConstants.MINUTE*15);
groupCache = CacheFactory.createCache("Group");
// A cache for meta-data around groups: count, group names, groups associated with
// a particular user
groupMetaCache = CacheManager.initializeCache("Group Metadata Cache", "groupMeta",
512 * 1024, JiveConstants.MINUTE*15);
groupMetaCache = CacheFactory.createCache("Group Metadata Cache");
// Load a group provider.
String className = JiveGlobals.getXMLProperty("provider.group.className",
......
......@@ -12,7 +12,7 @@ package org.jivesoftware.openfire.http;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
......@@ -33,8 +33,7 @@ public class ResourceServlet extends HttpServlet {
private static long expiresOffset = 3600 * 24 * 10; // 10 days util client cache expires
private boolean debug = false;
private boolean disableCompression = false;
private static Cache<String, byte[]> cache = CacheManager.initializeCache(
"Javascript Cache", "javascript", 128 * 1024, expiresOffset);
private static Cache<String, byte[]> cache = CacheFactory.createCache("Javascript Cache");
public void init(ServletConfig config) throws ServletException {
super.init(config);
......
......@@ -13,7 +13,7 @@ package org.jivesoftware.openfire.ldap;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.auth.AuthProvider;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.user.UserNotFoundException;
......@@ -48,12 +48,8 @@ public class LdapAuthProvider implements AuthProvider {
public LdapAuthProvider() {
manager = LdapManager.getInstance();
if (JiveGlobals.getXMLProperty("ldap.authCache.enabled", false)) {
int maxSize = JiveGlobals.getXMLProperty("ldap.authCache.size", 512*1024);
long maxLifetime = (long)JiveGlobals.getXMLProperty("ldap.authCache.maxLifetime",
(int)JiveConstants.HOUR * 2);
String cacheName = "LDAP Authentication";
CacheManager.initializeCache(cacheName, "ldap", maxSize, maxLifetime);
authCache = CacheManager.getCache(cacheName);
authCache = CacheFactory.createCache(cacheName);
}
}
......
......@@ -2,7 +2,7 @@ package org.jivesoftware.openfire.privacy;
import org.dom4j.Element;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
......@@ -53,8 +53,7 @@ public class PrivacyListManager {
private PrivacyListManager() {
// Create the cache of privacy lists
String cacheName = "Privacy Lists";
CacheManager.initializeCache(cacheName, "listsCache",512 * 1024);
listsCache = CacheManager.getCache(cacheName);
listsCache = CacheFactory.createCache(cacheName);
}
/**
......
......@@ -12,7 +12,7 @@
package org.jivesoftware.openfire.roster;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.openfire.ChannelHandler;
import org.jivesoftware.openfire.RoutingTable;
......@@ -64,6 +64,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
public RosterManager() {
super("Roster Manager");
rosterCache = CacheFactory.createCache("Roster");
}
/**
......@@ -75,12 +76,6 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
* to a known entity on the server.
*/
public Roster getRoster(String username) throws UserNotFoundException {
if (rosterCache == null) {
rosterCache = CacheManager.getCache("Roster");
}
if (rosterCache == null) {
throw new UserNotFoundException("Could not load caches");
}
Roster roster = rosterCache.get(username);
if (roster == null) {
// Synchronize using a unique key so that other threads loading the User
......@@ -122,7 +117,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
}
}
// Remove the cached roster from memory
CacheManager.getCache("Roster").remove(username);
rosterCache.remove(username);
// Get the rosters that have a reference to the deleted user
RosterItemProvider rosteItemProvider = RosterItemProvider.getInstance();
......@@ -336,7 +331,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
// Get the roster to update.
Roster roster = null;
if (server.isLocal(updatedUser)) {
roster = (Roster) CacheManager.getCache("Roster").get(updatedUser.getNode());
roster = rosterCache.get(updatedUser.getNode());
}
if (roster != null) {
// Update the roster with the new group display name
......@@ -491,7 +486,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
catch (UserNotFoundException e) {
continue;
}
roster = (Roster) CacheManager.getCache("Roster").get(userToUpdate.getNode());
roster = rosterCache.get(userToUpdate.getNode());
}
// Only update rosters in memory
if (roster != null) {
......@@ -529,7 +524,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
catch (UserNotFoundException e) {
continue;
}
roster = (Roster) CacheManager.getCache("Roster").get(userToUpdate.getNode());
roster = rosterCache.get(userToUpdate.getNode());
}
// Only update rosters in memory
if (roster != null) {
......@@ -570,7 +565,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
// Get the roster of the added user.
Roster addedUserRoster = null;
if (server.isLocal(addedUser)) {
addedUserRoster = (Roster) CacheManager.getCache("Roster").get(addedUser.getNode());
addedUserRoster = rosterCache.get(addedUser.getNode());
}
// Iterate on all the affected users and update their rosters
......@@ -586,7 +581,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
catch (UserNotFoundException e) {
continue;
}
roster = (Roster) CacheManager.getCache("Roster").get(userToUpdate.getNode());
roster = rosterCache.get(userToUpdate.getNode());
}
// Only update rosters in memory
if (roster != null) {
......@@ -595,7 +590,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
// Check if the roster is still not in memory
if (addedUserRoster == null && server.isLocal(addedUser)) {
addedUserRoster =
(Roster) CacheManager.getCache("Roster").get(addedUser.getNode());
rosterCache.get(addedUser.getNode());
}
// Update the roster of the newly added group user.
if (addedUserRoster != null) {
......@@ -639,7 +634,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
// Get the roster of the deleted user.
Roster deletedUserRoster = null;
if (server.isLocal(deletedUser)) {
deletedUserRoster = (Roster) CacheManager.getCache("Roster").get(deletedUser.getNode());
deletedUserRoster = rosterCache.get(deletedUser.getNode());
}
// Iterate on all the affected users and update their rosters
......@@ -654,7 +649,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
catch (UserNotFoundException e) {
continue;
}
roster = (Roster) CacheManager.getCache("Roster").get(userToUpdate.getNode());
roster = rosterCache.get(userToUpdate.getNode());
}
// Only update rosters in memory
if (roster != null) {
......@@ -663,7 +658,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
// Check if the roster is still not in memory
if (deletedUserRoster == null && server.isLocal(deletedUser)) {
deletedUserRoster =
(Roster) CacheManager.getCache("Roster").get(deletedUser.getNode());
rosterCache.get(deletedUser.getNode());
}
// Update the roster of the newly deleted group user.
if (deletedUserRoster != null) {
......
......@@ -17,7 +17,7 @@ import org.dom4j.DocumentHelper;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.PresenceManager;
import org.jivesoftware.openfire.SessionManager;
......@@ -469,8 +469,8 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
super.initialize(server);
this.server = server;
offlinePresenceCache = CacheManager.initializeCache("Offline Presence Cache", "offlinePresence", 512*1024);
lastActivityCache = CacheManager.initializeCache("Last Activity Cache", "lastActivity", 128*1024);
offlinePresenceCache = CacheFactory.createCache("Offline Presence Cache");
lastActivityCache = CacheFactory.createCache("Last Activity Cache");
deliverer = server.getPacketDeliverer();
sessionManager = server.getSessionManager();
......
......@@ -14,13 +14,14 @@ package org.jivesoftware.openfire.user;
import org.dom4j.Element;
import org.jivesoftware.openfire.IQResultListener;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.event.UserEventListener;
import org.jivesoftware.stringprep.Stringprep;
import org.jivesoftware.stringprep.StringprepException;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
......@@ -47,11 +48,9 @@ public class UserManager implements IQResultListener {
static {
// Initialize caches.
userCache = CacheManager.initializeCache("User", "userCache", 512 * 1024,
JiveConstants.MINUTE*30);
remoteUsersCache = CacheManager.initializeCache("Remote Users Existence", "remoteUsersCache",
512 * 1024, JiveConstants.MINUTE*30);
CacheManager.initializeCache("Roster", "username2roster", 512 * 1024);
userCache = CacheFactory.createCache("User");
remoteUsersCache = CacheFactory.createCache("Remote Users Exixtence");
// Load a user provider.
initProvider();
......
......@@ -14,7 +14,7 @@ package org.jivesoftware.openfire.vcard;
import org.dom4j.Element;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
......@@ -61,7 +61,7 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
public VCardManager() {
super("VCard Manager");
String cacheName = "VCard";
vcardCache = CacheManager.initializeCache(cacheName, "vcardCache", 512 * 1024);
vcardCache = CacheFactory.createCache(cacheName);
this.eventHandler = new EventHandler();
}
......
......@@ -16,7 +16,7 @@ import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
......@@ -79,8 +79,8 @@ public class FaviconServlet extends HttpServlet {
e.printStackTrace();
}
// Initialize caches.
missesCache = CacheManager.initializeCache("Favicon Misses", "faviconMisses", 128 * 1024);
hitsCache = CacheManager.initializeCache("Favicon Hits", "faviconHits", 128 * 1024);
missesCache = CacheFactory.createCache("Favicon Misses");
hitsCache = CacheFactory.createCache("Favicon Hits");
}
/**
......
......@@ -20,6 +20,7 @@ import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheManager;
import org.jivesoftware.util.cache.CacheFactory;
import java.io.*;
import java.net.URL;
......@@ -357,14 +358,12 @@ public class WebManager extends WebBean {
}
public Cache[] getCaches() {
List<Cache> caches = new ArrayList<Cache>(CacheManager.getCaches());
Collections.sort(caches, new Comparator() {
public int compare(Object o1, Object o2) {
Cache cache1 = (Cache)o1;
Cache cache2 = (Cache)o2;
Cache[] caches =CacheFactory.getAllCaches();
Arrays.sort(caches, new Comparator<Cache>() {
public int compare(Cache cache1, Cache cache2) {
return cache1.getName().toLowerCase().compareTo(cache2.getName().toLowerCase());
}
});
return caches.toArray(new Cache[]{});
return caches;
}
}
\ No newline at end of file
......@@ -10,6 +10,12 @@ package org.jivesoftware.util.cache;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.InitializationException;
import org.jivesoftware.util.JiveProperties;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.XMPPServerListener;
import org.jivesoftware.openfire.pubsub.Node;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
......@@ -146,28 +152,13 @@ public class CacheFactory {
}
JiveGlobals.setXMLProperty(CLUSTER_PROPERTY_NAME, String.valueOf(enabled));
if (!enabled) {
clusteringEnabled = false;
CacheFactoryStrategy clusteredFactory = cacheFactoryStrategy;
cacheFactoryStrategy = (CacheFactoryStrategy) Class.forName(localCacheFactoryClass)
.newInstance();
// Loop through clustered caches and change them to local caches.
for (String cacheName : caches.keySet()) {
CacheWrapper wrapper = (CacheWrapper) caches.get(cacheName);
wrapper.setWrappedCache(cacheFactoryStrategy.createCache(cacheName));
}
// Stop the cluster
clusteredFactory.stopCluster();
fireClusteringStopped();
stopClustering();
}
else {
// Reload Jive properties. This will ensure that this nodes copy of the
// properties starts correct.
//TODO see if there is something analagous in openfire
// DbJiveProperties.getInstance().init();
startClustering();
JiveProperties.getInstance().init();
startClustering();
}
}
......@@ -245,9 +236,9 @@ public class CacheFactory {
* as the system will have to do extra work to recover from a non-clean shutdown.
* If clustering is not enabled, this method will do nothing.
*/
public static synchronized void shutdownClusteringService() {
public static synchronized void shutdown() {
Log.debug("Shutting down clustered cache service.");
cacheFactoryStrategy.stopCluster();
stopClustering();
}
public static void addClusteringListener(ClusteringListener listener) {
......@@ -311,9 +302,15 @@ public class CacheFactory {
private volatile boolean destroyed = false;
public void run() {
XMPPServer.getInstance().addServerListener(new XMPPServerListener() {
public void serverStarted() {}
public void serverStopping() {
destroyed = true;
}
});
// Run the timer indefinitely.
//TODO set the destroyed flag through some listener
while (!destroyed) {
// Publish cache stats for this cluster node (assuming clustering is
// enabled and there are stats to publish).
......@@ -360,6 +357,29 @@ public class CacheFactory {
}
}
private static void stopClustering() {
try {
CacheFactoryStrategy clusteredFactory = cacheFactoryStrategy;
cacheFactoryStrategy = (CacheFactoryStrategy) Class.forName(localCacheFactoryClass)
.newInstance();
// Loop through clustered caches and change them to local caches.
for (String cacheName : caches.keySet()) {
CacheWrapper wrapper = (CacheWrapper) caches.get(cacheName);
wrapper.setWrappedCache(cacheFactoryStrategy.createCache(cacheName));
}
clusteringEnabled = false;
// Stop the cluster
clusteredFactory.stopCluster();
fireClusteringStopped();
}
catch (Exception e) {
Log.error("Unable to stop clustering - continuing in clustered mode", e);
}
}
/**
* Creates a new Cluster Task that will execute the wrapped task and ensure
* that any DAO context is also closed after the execution of the task.
......
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