001    /**
002     * Copyright (c) 2000-2011 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.cluster;
016    
017    import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterEvent;
018    import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterEventType;
019    import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterLinkUtil;
020    import com.liferay.portal.kernel.util.StringPool;
021    
022    import net.sf.ehcache.CacheException;
023    import net.sf.ehcache.Ehcache;
024    import net.sf.ehcache.Element;
025    import net.sf.ehcache.distribution.CacheReplicator;
026    
027    /**
028     * @author Shuyang Zhou
029     */
030    public class EhcachePortalCacheClusterReplicator implements CacheReplicator {
031    
032            public boolean alive() {
033                    return true;
034            }
035    
036            @Override
037            public Object clone() throws CloneNotSupportedException {
038                    return super.clone();
039            }
040    
041            public void dispose() {
042            }
043    
044            public boolean isReplicateUpdatesViaCopy() {
045                    return false;
046            }
047    
048            public boolean notAlive() {
049                    return false;
050            }
051    
052            public void notifyElementEvicted(Ehcache ehcache, Element element) {
053            }
054    
055            public void notifyElementExpired(Ehcache ehcache, Element element) {
056            }
057    
058            public void notifyElementPut(Ehcache ehcache, Element element)
059                    throws CacheException {
060            }
061    
062            public void notifyElementRemoved(Ehcache ehcache, Element element)
063                    throws CacheException {
064    
065                    PortalCacheClusterEvent portalCacheClusterEvent =
066                            new PortalCacheClusterEvent(
067                                    ehcache.getName(), element.getKey(),
068                                    PortalCacheClusterEventType.REMOVE);
069    
070                    PortalCacheClusterLinkUtil.sendEvent(portalCacheClusterEvent);
071            }
072    
073            public void notifyElementUpdated(Ehcache ehcache, Element element)
074                    throws CacheException {
075    
076                    PortalCacheClusterEvent portalCacheClusterEvent =
077                            new PortalCacheClusterEvent(
078                                    ehcache.getName(), element.getKey(),
079                                    PortalCacheClusterEventType.UPDATE);
080    
081                    PortalCacheClusterLinkUtil.sendEvent(portalCacheClusterEvent);
082            }
083    
084            public void notifyRemoveAll(Ehcache ehcache) {
085                    PortalCacheClusterEvent portalCacheClusterEvent =
086                            new PortalCacheClusterEvent(
087                                    ehcache.getName(), StringPool.BLANK,
088                                    PortalCacheClusterEventType.REMOVEALL);
089    
090                    PortalCacheClusterLinkUtil.sendEvent(portalCacheClusterEvent);
091            }
092    
093    }