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 public CacheManagerPeerProvider createCachePeerProvider(
039 CacheManager cacheManager, Properties properties) {
040
041 if (_log.isDebugEnabled()) {
042 _log.debug("Creating JGroups peer provider");
043 }
044
045 String clusterName = properties.getProperty("clusterName");
046
047 if (clusterName == null) {
048 clusterName = _DEFAULT_CLUSTER_NAME;
049 }
050
051 if (_log.isDebugEnabled()) {
052 _log.debug("Cluster name " + clusterName);
053 }
054
055 String channelProperties = properties.getProperty("channelProperties");
056
057 if (channelProperties != null) {
058 channelProperties = channelProperties.replaceAll(
059 StringPool.SPACE, StringPool.BLANK);
060
061 if (Validator.isNull(channelProperties)) {
062 channelProperties = null;
063 }
064 }
065
066 if (_log.isDebugEnabled()) {
067 _log.debug("Channel properties " + channelProperties);
068 }
069
070 return new JGroupsManager(cacheManager, clusterName, channelProperties);
071 }
072
073 private static final String _DEFAULT_CLUSTER_NAME = "Ehcache";
074
075 private static Log _log = LogFactoryUtil.getLog(
076 JGroupsCacheManagerPeerProviderFactory.class);
077
078 }