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.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 + " " + 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            @Override
051            public CacheEventListener createCacheEventListener(Properties properties) {
052                    return _cacheEventListenerFactory.createCacheEventListener(properties);
053            }
054    
055            private static Log _log = LogFactoryUtil.getLog(
056                    LiferayCacheEventListenerFactory.class);
057    
058            private CacheEventListenerFactory _cacheEventListenerFactory;
059    
060    }