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