001
014
015 package com.liferay.portal.cache.ehcache;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.kernel.util.Validator;
021
022 import java.util.Properties;
023
024 import net.sf.ehcache.CacheManager;
025 import net.sf.ehcache.distribution.CacheManagerPeerProvider;
026 import net.sf.ehcache.distribution.CacheManagerPeerProviderFactory;
027
028
035 public class JGroupsCacheManagerPeerProviderFactory
036 extends CacheManagerPeerProviderFactory {
037
038 @Override
039 public CacheManagerPeerProvider createCachePeerProvider(
040 CacheManager cacheManager, Properties properties) {
041
042 if (_log.isDebugEnabled()) {
043 _log.debug("Creating JGroups peer provider");
044 }
045
046 String clusterName = properties.getProperty("clusterName");
047
048 if (clusterName == null) {
049 clusterName = _DEFAULT_CLUSTER_NAME;
050 }
051
052 if (_log.isDebugEnabled()) {
053 _log.debug("Cluster name " + clusterName);
054 }
055
056 String channelProperties = properties.getProperty("channelProperties");
057
058 if (channelProperties != null) {
059 channelProperties = channelProperties.replaceAll(
060 StringPool.SPACE, StringPool.BLANK);
061
062 if (Validator.isNull(channelProperties)) {
063 channelProperties = null;
064 }
065 }
066
067 if (_log.isDebugEnabled()) {
068 _log.debug("Channel properties " + channelProperties);
069 }
070
071 return new JGroupsManager(cacheManager, clusterName, channelProperties);
072 }
073
074 private static final String _DEFAULT_CLUSTER_NAME = "Ehcache";
075
076 private static Log _log = LogFactoryUtil.getLog(
077 JGroupsCacheManagerPeerProviderFactory.class);
078
079 }