org.jivesoftware.openfire.container.PluginCacheRegistry Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.container;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.cache.CacheFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A simple registry of cache configuration data for plugins.
*/
public class PluginCacheRegistry {
private static final Logger Log = LoggerFactory.getLogger(PluginCacheRegistry.class);
private static final PluginCacheRegistry instance = new PluginCacheRegistry();
private Map extraCacheMappings = new HashMap<>();
private Map> pluginCaches = new HashMap<>();
public static PluginCacheRegistry getInstance() {
return instance;
}
private PluginCacheRegistry() {
}
/**
* Registers cache configuration data for a give cache and plugin.
*
* @param pluginName the name of the plugin which will use the cache.
* @param info the cache configuration data.
*/
public void registerCache(String pluginName, CacheInfo info) {
extraCacheMappings.put(info.getCacheName(), info);
List caches = pluginCaches.get(pluginName);
if (caches == null) {
caches = new ArrayList<>();
pluginCaches.put(pluginName, caches);
}
caches.add(info);
// Set system properties for this cache
CacheFactory.setCacheTypeProperty(info.getCacheName(), info.getType().getName());
CacheFactory.setMaxSizeProperty(info.getCacheName(), getMaxSizeFromProperty(info));
CacheFactory.setMaxLifetimeProperty(info.getCacheName(), getMaxLifetimeFromProperty(info));
CacheFactory.setMinCacheSize(info.getCacheName(), getMinSizeFromProperty(info));
}
/**
* Unregisters all caches for the given plugin.
*
* @param pluginName the name of the plugin whose caches will be unregistered.
*/
public void unregisterCaches(String pluginName) {
List caches = pluginCaches.remove(pluginName);
if (caches != null) {
for (CacheInfo info : caches) {
extraCacheMappings.remove(info.getCacheName());
// Check if other cluster nodes have this plugin installed
Collection