001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
029     * <p>
030     * See http://issues.liferay.com/browse/LPS-11061.
031     * </p>
032     *
033     * @author Tina Tian
034     */
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    }