001    /**
002     * Copyright (c) 2000-2010 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.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            public Object clone() throws CloneNotSupportedException {
037                    return super.clone();
038            }
039    
040            public void dispose() {
041            }
042    
043            public boolean isReplicateUpdatesViaCopy() {
044                    return false;
045            }
046    
047            public boolean notAlive() {
048                    return false;
049            }
050    
051            public void notifyElementEvicted(Ehcache ehcache, Element element) {
052                    PortalCacheClusterLinkUtil.sendEvent(
053                            new PortalCacheClusterEvent(
054                                    ehcache.getName(), element.getKey(),
055                                    PortalCacheClusterEventType.EVICTED));
056            }
057    
058            public void notifyElementExpired(Ehcache ehcache, Element element) {
059                    PortalCacheClusterLinkUtil.sendEvent(
060                            new PortalCacheClusterEvent(
061                                    ehcache.getName(), element.getKey(),
062                                    PortalCacheClusterEventType.EXPIRED));
063            }
064    
065            public void notifyElementPut(Ehcache ehcache, Element element)
066                    throws CacheException {
067                    PortalCacheClusterLinkUtil.sendEvent(
068                            new PortalCacheClusterEvent(
069                                    ehcache.getName(), element.getKey(),
070                                    PortalCacheClusterEventType.PUT));
071            }
072    
073            public void notifyElementRemoved(Ehcache ehcache, Element element)
074                    throws CacheException {
075                    PortalCacheClusterLinkUtil.sendEvent(
076                            new PortalCacheClusterEvent(
077                                    ehcache.getName(), element.getKey(),
078                                    PortalCacheClusterEventType.REMOVE));
079            }
080    
081            public void notifyElementUpdated(Ehcache ehcache, Element element)
082                    throws CacheException {
083                    PortalCacheClusterLinkUtil.sendEvent(
084                            new PortalCacheClusterEvent(
085                                    ehcache.getName(), element.getKey(),
086                                    PortalCacheClusterEventType.UPDATE));
087            }
088    
089            public void notifyRemoveAll(Ehcache ehcache) {
090                    PortalCacheClusterLinkUtil.sendEvent(
091                            new PortalCacheClusterEvent(
092                                    ehcache.getName(), StringPool.BLANK,
093                                    PortalCacheClusterEventType.REMOVEALL));
094            }
095    
096    }