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