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