- 注册时间
- 2011-3-22
- 最后登录
- 2013-6-27
- 在线时间
- 11644 小时
- 阅读权限
- 150
- 积分
- 62779
- 帖子
- 28923
- 精华
- 1
- UID
- 6
|
- 1.1.10 Cache Factory
- /**
- * Creates Cache objects. The returned cacheswill either be local or clustered
- * depending on the clustering enabled settingand a user's license.<p>
- * <p/>
- * When clustered caching is turned on, cacheusage statistics for all caches
- * that have been created are periodicallypublished to the clustered cache
- * named "opt-$cacheStats".
- *
- */
- public class CacheFactory {
- localCacheFactoryClass =JiveGlobals.getProperty(LOCAL_CACHE_PROPERTY_NAME,
- "org.jivesoftware.util.cache.DefaultLocalCacheStrategy");
- clusteredCacheFactoryClass =JiveGlobals.getProperty(CLUSTERED_CACHE_PROPERTY_NAME,
- "com.jivesoftware.util.cache.CoherenceClusteredCacheFactory");
- /**
- * Sets a local property which overrides the maximum cache size asconfigured 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));
- }
-
-
- /**
- * Sets a local property which overrides the maximum cache entry lifetimeas configured in coherence-cache-config.xml
- * for the supplied cache name.
- * @param cacheName the name of the cache to store a value for.
- * @param lifetime the maximum cache entry lifetime.
- */
- public static void setMaxLifetimeProperty(String cacheName, long lifetime) {
- cacheName = cacheName.replaceAll(" ", "");
- JiveGlobals.setProperty(("cache." + cacheName + ".maxLifetime"), Long.toString(lifetime));
- }
-
- public static boolean hasMaxLifetimeFromProperty(String cacheName) {
- return hasCacheProperty(cacheName, ".maxLifetime");
- }
-
- public static void setCacheTypeProperty(String cacheName, String type) {
- cacheName = cacheName.replaceAll(" ", "");
- JiveGlobals.setProperty("cache." + cacheName + ".type", type);
- }
-
- public static String getCacheTypeProperty(String cacheName) {
- cacheName = cacheName.replaceAll(" ", "");
- return JiveGlobals.getProperty("cache." + cacheName + ".type");
- }
-
- public static void setMinCacheSize(String cacheName, long size) {
- cacheName = cacheName.replaceAll(" ", "");
- JiveGlobals.setProperty("cache." + cacheName + ".min", Long.toString(size));
- }
-
- public static long getMinCacheSize(String cacheName) {
- return getCacheProperty(cacheName, ".min", 0);
- }
-
- private static long getCacheProperty(String cacheName, String suffix, long defaultValue){
- // First check if user is overwritingdefault value using a system property for the cache name
- String propName = "cache." + cacheName.replaceAll("", "") + suffix;
- String sizeProp = JiveGlobals.getProperty(propName);
- if (sizeProp == null && cacheNames.containsKey(cacheName)) {
- // No system property was foundfor the cache name so try now with short name
- propName = "cache." +cacheNames.get(cacheName) + suffix;
- sizeProp =JiveGlobals.getProperty(propName);
- }
- if (sizeProp != null) {
- try {
- returnLong.parseLong(sizeProp);
- }
- catch(NumberFormatException nfe) {
- Log.warn("Unable to parse " + propName + " usingdefault value.");
- }
- }
- // Check if there is a default size value for this cache
- Long defaultSize =cacheProps.get(propName);
- return defaultSize ==null ? defaultValue : defaultSize;
- }
- 1.1.11 Local Outgoing Server Session
- boolean useTLS = JiveGlobals.getBooleanProperty("xmpp.server.tls.enabled", true);
- boolean needed = JiveGlobals.getBooleanProperty("xmpp.server.certificate.verify", true) &&
- JiveGlobals.getBooleanProperty("xmpp.server.certificate.verify.chain", true) &&
- !JiveGlobals.getBooleanProperty("xmpp.server.certificate.accept-selfsigned", false);
- String policyName =JiveGlobals.getProperty("xmpp.server.compression.policy",
- Connection.CompressionPolicy.disabled.toString());
- 1.1.12 Local Incoming Server Session
- String policyName =JiveGlobals.getProperty("xmpp.server.compression.policy",
- 1.1.13 Local Connection Multiplexer Session
- String policyName =JiveGlobals.getProperty("xmpp.multiplex.tls.policy",
- Connection.TLSPolicy.disabled.toString());
- tlsPolicy =Connection.TLSPolicy.valueOf(policyName);
-
- // Set the Compression policy stored as a system property
- policyName = JiveGlobals.getProperty("xmpp.multiplex.compression.policy",
- Connection.CompressionPolicy.disabled.toString());
-
- 1.1.14 Outgoing Session Promise
- int maxThreads = JiveGlobals.getIntProperty("xmpp.server.outgoing.max.threads", 20);
- int queueSize = JiveGlobals.getIntProperty("xmpp.server.outgoing.queue", 50);
- if (maxThreads < 10) {
- // Ensure that the max number ofthreads in the pool is at least 10
- maxThreads = 10;
- }
- threadPool =
- newThreadPoolExecutor(maxThreads/4, maxThreads, 60, TimeUnit.SECONDS,
- new LinkedBlockingQueue<Runnable>(queueSize),
- newThreadPoolExecutor.CallerRunsPolicy());
-
- // Start the thread that willconsume the queued packets. Each pending packet will
- // be actually processed by athread of the pool (when available). If an error occurs
- // while creating the remotesession or sending the packet then a packet with error 502
- // will be sent to the sender ofthe packet
- 1.1.15 Remote Server Manager
- public static boolean canAccess(String domain) {
- // If s2s is disabled then it isnot possible to send packets to remote servers or
- // receive packets from remoteservers
- if (!JiveGlobals.getBooleanProperty("xmpp.server.socket.active", true)) {
- return false;
- }
-
- /**
- * Returns the number of milliseconds towait to connect to a remote server or read
- * data from a remote server. Defaulttimeout value is 20 seconds. Configure the
- * <tt>xmpp.server.read.timeout</tt> globalproperty to override the default value.
- *
- * @return the numberof milliseconds to wait to connect to a remote server or read
- * data from a remote server.
- */
- public static int getSocketTimeout() {
- return JiveGlobals.getIntProperty("xmpp.server.read.timeout", 120000);
- }
-
-
- /**
- * Returns the remote port to connect forthe specified remote server. If no port was
- * defined then use the default port (e.g.5269).
- *
- * @param domain thedomain of the remote server to get the remote port to connect to.
- * @return the remoteport to connect for the specified remote server.
- */
- public static int getPortForServer(String domain) {
- int port = JiveGlobals.getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);
- RemoteServerConfiguration config =getConfiguration(domain);
- if (config != null) {
- port = config.getRemotePort();
- if (port == 0) {
- port = JiveGlobals
- .getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);
- }
- }
- return port;
- }
-
- /**
- * Returns the permission policy being usedfor new XMPP entities that are trying to
- * connect to the server. There are twotypes of policies: 1) blacklist: where any entity
- * is allowed to connect to the serverexcept for those listed in the black list and
- * 2) whitelist: where only the entitieslisted in the white list are allowed to connect to
- * the server.
- *
- * @return thepermission policy being used for new XMPP entities that are trying to
- * connect to the server.
- */
- public static PermissionPolicy getPermissionPolicy() {
- try {
- return PermissionPolicy.valueOf(JiveGlobals.getProperty("xmpp.server.permission",
- PermissionPolicy.blacklist.toString()));
- }
- catch (Exception e){
- Log.error(e.getMessage(), e);
- returnPermissionPolicy.blacklist;
- }
- }
复制代码 |
|