001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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.StringUtil;
021    import com.liferay.portal.kernel.util.Validator;
022    
023    import java.util.Properties;
024    
025    import net.sf.ehcache.CacheManager;
026    import net.sf.ehcache.distribution.CacheManagerPeerProvider;
027    import net.sf.ehcache.distribution.CacheManagerPeerProviderFactory;
028    
029    /**
030     * <p>
031     * See https://issues.liferay.com/browse/LPS-11061.
032     * </p>
033     *
034     * @author Tina Tian
035     */
036    public class JGroupsCacheManagerPeerProviderFactory
037            extends CacheManagerPeerProviderFactory {
038    
039            @Override
040            public CacheManagerPeerProvider createCachePeerProvider(
041                    CacheManager cacheManager, Properties properties) {
042    
043                    if (_log.isDebugEnabled()) {
044                            _log.debug("Creating JGroups peer provider");
045                    }
046    
047                    String clusterName = properties.getProperty("clusterName");
048    
049                    if (clusterName == null) {
050                            clusterName = _DEFAULT_CLUSTER_NAME;
051                    }
052    
053                    if (_log.isDebugEnabled()) {
054                            _log.debug("Cluster name " + clusterName);
055                    }
056    
057                    String channelProperties = properties.getProperty("channelProperties");
058    
059                    if (channelProperties != null) {
060                            channelProperties = StringUtil.replace(
061                                    channelProperties, StringPool.SPACE, StringPool.BLANK);
062    
063                            if (Validator.isNull(channelProperties)) {
064                                    channelProperties = null;
065                            }
066                    }
067    
068                    if (_log.isDebugEnabled()) {
069                            _log.debug("Channel properties " + channelProperties);
070                    }
071    
072                    return new JGroupsManager(cacheManager, clusterName, channelProperties);
073            }
074    
075            private static final String _DEFAULT_CLUSTER_NAME = "Ehcache";
076    
077            private static final Log _log = LogFactoryUtil.getLog(
078                    JGroupsCacheManagerPeerProviderFactory.class);
079    
080    }