001    /**
002     * Copyright (c) 2000-2013 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.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    }