001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.event.CacheEventListener;
025    import net.sf.ehcache.event.CacheEventListenerFactory;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class LiferayCacheEventListenerFactory
031            extends CacheEventListenerFactory {
032    
033            public LiferayCacheEventListenerFactory() {
034                    String className = PropsValues.EHCACHE_CACHE_EVENT_LISTENER_FACTORY;
035    
036                    if (_log.isDebugEnabled()) {
037                            _log.debug("Instantiating " + className + " " + this.hashCode());
038                    }
039    
040                    try {
041                            _cacheEventListenerFactory =
042                                    (CacheEventListenerFactory)InstanceFactory.newInstance(
043                                            className);
044                    }
045                    catch (Exception e) {
046                            throw new RuntimeException(e);
047                    }
048            }
049    
050            public CacheEventListener createCacheEventListener(Properties properties) {
051                    return _cacheEventListenerFactory.createCacheEventListener(properties);
052            }
053    
054            private static Log _log = LogFactoryUtil.getLog(
055                    LiferayCacheEventListenerFactory.class);
056    
057            private CacheEventListenerFactory _cacheEventListenerFactory;
058    
059    }