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.InstanceFactory;
020    import com.liferay.portal.util.PropsValues;
021    
022    import java.util.Properties;
023    
024    import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
025    import net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class LiferayBootstrapCacheLoaderFactory
031            extends BootstrapCacheLoaderFactory {
032    
033            public LiferayBootstrapCacheLoaderFactory() {
034                    String className = PropsValues.EHCACHE_BOOTSTRAP_CACHE_LOADER_FACTORY;
035    
036                    if (PropsValues.CLUSTER_LINK_ENABLED &&
037                            PropsValues.EHCACHE_CLUSTER_LINK_REPLICATION_ENABLED) {
038    
039                            className =
040                                    EhcacheStreamBootstrapCacheLoaderFactory.class.getName();
041                    }
042    
043                    if (_log.isDebugEnabled()) {
044                            _log.debug("Instantiating " + className + " " + hashCode());
045                    }
046    
047                    try {
048                            _bootstrapCacheLoaderFactory =
049                                    (BootstrapCacheLoaderFactory)InstanceFactory.newInstance(
050                                            className);
051                    }
052                    catch (Exception e) {
053                            throw new RuntimeException(e);
054                    }
055            }
056    
057            @Override
058            public BootstrapCacheLoader createBootstrapCacheLoader(
059                    Properties properties) {
060    
061                    return _bootstrapCacheLoaderFactory.createBootstrapCacheLoader(
062                            properties);
063            }
064    
065            private static Log _log = LogFactoryUtil.getLog(
066                    LiferayBootstrapCacheLoaderFactory.class);
067    
068            private BootstrapCacheLoaderFactory _bootstrapCacheLoaderFactory;
069    
070    }