📄 cachefactory.java
字号:
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.util.cache;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.XMPPServerListener;
import org.jivesoftware.openfire.cluster.ClusterEventListener;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.cluster.ClusterNodeInfo;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginClassLoader;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.util.InitializationException;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
/**
* Creates Cache objects. The returned caches will either be local or clustered
* depending on the clustering enabled setting and a user's license.<p>
* <p/>
* When clustered caching is turned on, cache usage statistics for all caches
* that have been created are periodically published to the clustered cache
* named "opt-$cacheStats".
*
*/
public class CacheFactory {
public static String LOCAL_CACHE_PROPERTY_NAME = "cache.clustering.local.class";
public static String CLUSTERED_CACHE_PROPERTY_NAME = "cache.clustering.clustered.class";
private static boolean clusteringStarted = false;
private static boolean clusteringStarting = false;
/**
* Storage for all caches that get created.
*/
private static Map<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
private static String localCacheFactoryClass;
private static String clusteredCacheFactoryClass;
private static CacheFactoryStrategy cacheFactoryStrategy;
private static Thread statsThread;
public static final int DEFAULT_MAX_CACHE_SIZE = 1024 * 256;
public static final long DEFAULT_MAX_CACHE_LIFETIME = 6 * JiveConstants.HOUR;
/**
* This map contains property names which were used to store cache configuration data
* in local xml properties in previous versions.
*/
private static final Map<String, String> cacheNames = new HashMap<String, String>();
/**
* Default properties to use for local caches. Default properties can be overridden
* by setting the corresponding system properties.
*/
private static final Map<String, Long> cacheProps = new HashMap<String, Long>();
static {
localCacheFactoryClass = JiveGlobals.getProperty(LOCAL_CACHE_PROPERTY_NAME,
"org.jivesoftware.util.cache.DefaultLocalCacheStrategy");
clusteredCacheFactoryClass = JiveGlobals.getProperty(CLUSTERED_CACHE_PROPERTY_NAME,
"com.jivesoftware.util.cache.CoherenceClusteredCacheFactory");
cacheNames.put("Favicon Hits", "faviconHits");
cacheNames.put("Favicon Misses", "faviconMisses");
cacheNames.put("Group", "group");
cacheNames.put("Group Metadata Cache", "groupMeta");
cacheNames.put("Javascript Cache", "javascript");
cacheNames.put("Last Activity Cache", "lastActivity");
cacheNames.put("Multicast Service", "multicast");
cacheNames.put("Offline Message Size", "offlinemessage");
cacheNames.put("Offline Presence Cache", "offlinePresence");
cacheNames.put("Privacy Lists", "listsCache");
cacheNames.put("Remote Users Existence", "remoteUsersCache");
cacheNames.put("Roster", "username2roster");
cacheNames.put("User", "userCache");
cacheNames.put("Locked Out Accounts", "lockOutCache");
cacheNames.put("VCard", "vcardCache");
cacheNames.put("File Transfer Cache", "fileTransfer");
cacheNames.put("File Transfer", "transferProxy");
cacheNames.put("POP3 Authentication", "pop3");
cacheNames.put("LDAP Authentication", "ldap");
cacheNames.put("Routing Servers Cache", "routeServer");
cacheNames.put("Routing Components Cache", "routeComponent");
cacheNames.put("Routing Users Cache", "routeUser");
cacheNames.put("Routing AnonymousUsers Cache", "routeAnonymousUser");
cacheNames.put("Routing User Sessions", "routeUserSessions");
cacheNames.put("Components Sessions", "componentsSessions");
cacheNames.put("Connection Managers Sessions", "connManagerSessions");
cacheNames.put("Incoming Server Sessions", "incServerSessions");
cacheNames.put("Sessions by Hostname", "sessionsHostname");
cacheNames.put("Secret Keys Cache", "secretKeys");
cacheNames.put("Validated Domains", "validatedDomains");
cacheNames.put("Directed Presences", "directedPresences");
cacheNames.put("Disco Server Features", "serverFeatures");
cacheNames.put("Disco Server Items", "serverItems");
cacheNames.put("Remote Server Configurations", "serversConfigurations");
cacheNames.put("Entity Capabilities", "entityCapabilities");
cacheNames.put("Entity Capabilities Users", "entityCapabilitiesUsers");
cacheNames.put("Entity Capabilities Pending Hashes", "entityCapabilitiesPendingHashes");
cacheProps.put("cache.fileTransfer.size", 128 * 1024l);
cacheProps.put("cache.fileTransfer.maxLifetime", 1000 * 60 * 10l);
cacheProps.put("cache.multicast.size", 128 * 1024l);
cacheProps.put("cache.multicast.maxLifetime", JiveConstants.DAY);
cacheProps.put("cache.offlinemessage.size", 100 * 1024l);
cacheProps.put("cache.offlinemessage.maxLifetime", JiveConstants.HOUR * 12);
cacheProps.put("cache.pop3.size", 512 * 1024l);
cacheProps.put("cache.pop3.maxLifetime", JiveConstants.HOUR);
cacheProps.put("cache.transferProxy.size", -1l);
cacheProps.put("cache.transferProxy.maxLifetime", 1000 * 60 * 10l);
cacheProps.put("cache.group.size", 1024 * 1024l);
cacheProps.put("cache.group.maxLifetime", JiveConstants.MINUTE * 15);
cacheProps.put("cache.lockOutCache.size", 1024 * 1024l);
cacheProps.put("cache.lockOutCache.maxLifetime", JiveConstants.MINUTE * 15);
cacheProps.put("cache.groupMeta.size", 512 * 1024l);
cacheProps.put("cache.groupMeta.maxLifetime", JiveConstants.MINUTE * 15);
cacheProps.put("cache.javascript.size", 128 * 1024l);
cacheProps.put("cache.javascript.maxLifetime", 3600 * 24 * 10l);
cacheProps.put("cache.ldap.size", 512 * 1024l);
cacheProps.put("cache.ldap.maxLifetime", JiveConstants.HOUR * 2);
cacheProps.put("cache.listsCache.size", 512 * 1024l);
cacheProps.put("cache.offlinePresence.size", 512 * 1024l);
cacheProps.put("cache.lastActivity.size", 128 * 1024l);
cacheProps.put("cache.userCache.size", 512 * 1024l);
cacheProps.put("cache.userCache.maxLifetime", JiveConstants.MINUTE * 30);
cacheProps.put("cache.remoteUsersCache.size", 512 * 1024l);
cacheProps.put("cache.remoteUsersCache.maxLifetime", JiveConstants.MINUTE * 30);
cacheProps.put("cache.vcardCache.size", 512 * 1024l);
cacheProps.put("cache.faviconHits.size", 128 * 1024l);
cacheProps.put("cache.faviconMisses.size", 128 * 1024l);
cacheProps.put("cache.routeServer.size", -1l);
cacheProps.put("cache.routeServer.maxLifetime", -1l);
cacheProps.put("cache.routeComponent.size", -1l);
cacheProps.put("cache.routeComponent.maxLifetime", -1l);
cacheProps.put("cache.routeUser.size", -1l);
cacheProps.put("cache.routeUser.maxLifetime", -1l);
cacheProps.put("cache.routeAnonymousUser.size", -1l);
cacheProps.put("cache.routeAnonymousUser.maxLifetime", -1l);
cacheProps.put("cache.routeUserSessions.size", -1l);
cacheProps.put("cache.routeUserSessions.maxLifetime", -1l);
cacheProps.put("cache.componentsSessions.size", -1l);
cacheProps.put("cache.componentsSessions.maxLifetime", -1l);
cacheProps.put("cache.connManagerSessions.size", -1l);
cacheProps.put("cache.connManagerSessions.maxLifetime", -1l);
cacheProps.put("cache.incServerSessions.size", -1l);
cacheProps.put("cache.incServerSessions.maxLifetime", -1l);
cacheProps.put("cache.sessionsHostname.size", -1l);
cacheProps.put("cache.sessionsHostname.maxLifetime", -1l);
cacheProps.put("cache.secretKeys.size", -1l);
cacheProps.put("cache.secretKeys.maxLifetime", -1l);
cacheProps.put("cache.validatedDomains.size", -1l);
cacheProps.put("cache.validatedDomains.maxLifetime", -1l);
cacheProps.put("cache.directedPresences.size", -1l);
cacheProps.put("cache.directedPresences.maxLifetime", -1l);
cacheProps.put("cache.serverFeatures.size", -1l);
cacheProps.put("cache.serverFeatures.maxLifetime", -1l);
cacheProps.put("cache.serverItems.size", -1l);
cacheProps.put("cache.serverItems.maxLifetime", -1l);
cacheProps.put("cache.serversConfigurations.size", 128 * 1024l);
cacheProps.put("cache.serversConfigurations.maxLifetime", JiveConstants.MINUTE * 30);
cacheProps.put("cache.entityCapabilities.size", -1l);
cacheProps.put("cache.entityCapabilities.maxLifetime", JiveConstants.DAY * 2);
cacheProps.put("cache.entityCapabilitiesUsers.size", -1l);
cacheProps.put("cache.entityCapabilitiesUsers.maxLifetime", JiveConstants.DAY * 2);
cacheProps.put("cache.entityCapabilitiesPendingHashes.size", -1l);
cacheProps.put("cache.entityCapabilitiesPendingHashes.maxLifetime", JiveConstants.DAY * 2);
cacheProps.put("cache.pluginCacheInfo.size", -1l);
cacheProps.put("cache.pluginCacheInfo.maxLifetime", -1l);
}
private CacheFactory() {
}
/**
* If a local property is found for the supplied name which specifies a value for cache size, it is returned.
* Otherwise, the defaultSize argument is returned.
*
* @param cacheName the name of the cache to look up a corresponding property for.
* @return either the property value or the default value.
*/
public static long getMaxCacheSize(String cacheName) {
return getCacheProperty(cacheName, ".size", DEFAULT_MAX_CACHE_SIZE);
}
/**
* Sets a local property which overrides the maximum cache size as configured in coherence-cache-config.xml for the
* supplied cache name.
* @param cacheName the name of the cache to store a value for.
* @param size the maximum cache size.
*/
public static void setMaxSizeProperty(String cacheName, long size) {
cacheName = cacheName.replaceAll(" ", "");
JiveGlobals.setProperty("cache." + cacheName + ".size", Long.toString(size));
}
public static boolean hasMaxSizeFromProperty(String cacheName) {
return hasCacheProperty(cacheName, ".size");
}
/**
* If a local property is found for the supplied name which specifies a value for cache entry lifetime, it
* is returned. Otherwise, the defaultLifetime argument is returned.
*
* @param cacheName the name of the cache to look up a corresponding property for.
* @return either the property value or the default value.
*/
public static long getMaxCacheLifetime(String cacheName) {
return getCacheProperty(cacheName, ".maxLifetime", DEFAULT_MAX_CACHE_LIFETIME);
}
/**
* Sets a local property which overrides the maximum cache entry lifetime as configured in coherence-cache-config.xml
* for the supplied cache name.
* @param cacheName the name of the cache to store a value for.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -