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