001
014
015 package com.liferay.portal.nio.intraband.cache;
016
017 import com.liferay.portal.kernel.cache.PortalCache;
018 import com.liferay.portal.kernel.cache.PortalCacheManager;
019 import com.liferay.portal.kernel.nio.intraband.RegistrationReference;
020 import com.liferay.portal.nio.intraband.proxy.IntrabandProxyUtil;
021 import com.liferay.portal.nio.intraband.proxy.WarnLogExceptionHandler;
022
023 import java.io.Serializable;
024
025 import java.util.Map;
026 import java.util.concurrent.ConcurrentHashMap;
027
028
031 public abstract class BaseIntrabandPortalCacheManager
032 <K extends Serializable, V extends Serializable>
033 implements PortalCacheManager<K, V> {
034
035 public static Class<? extends PortalCache<?, ?>> getPortalCacheStubClass() {
036 return _STUB_CLASS;
037 }
038
039 @Override
040 public void destroy() {
041 _portalCaches.clear();
042 }
043
044 @Override
045 public PortalCache<K, V> getCache(String name) {
046 return getCache(name, false);
047 }
048
049 @Override
050 public PortalCache<K, V> getCache(String name, boolean blocking) {
051 PortalCache<K, V> portalCache = _portalCaches.get(name);
052
053 if (portalCache == null) {
054 portalCache = (PortalCache<K, V>)IntrabandProxyUtil.newStubInstance(
055 _STUB_CLASS, name, _registrationReference,
056 WarnLogExceptionHandler.INSTANCE);
057
058 _portalCaches.put(name, portalCache);
059 }
060
061 return portalCache;
062 }
063
064 @Override
065 public void removeCache(String name) {
066 _portalCaches.remove(name);
067 }
068
069 private static final Class<? extends PortalCache<?, ?>> _STUB_CLASS =
070 (Class<? extends PortalCache<?, ?>>)
071 IntrabandProxyUtil.getStubClass(
072 PortalCache.class, PortalCache.class.getName());
073
074 private final Map<String, PortalCache<K, V>> _portalCaches =
075 new ConcurrentHashMap<String, PortalCache<K, V>>();
076 private final RegistrationReference _registrationReference = null;
077
078 }