1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.cache.cluster;
16  
17  import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterEvent;
18  import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterEventType;
19  import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterLinkUtil;
20  import com.liferay.portal.kernel.util.StringPool;
21  
22  import net.sf.ehcache.CacheException;
23  import net.sf.ehcache.Ehcache;
24  import net.sf.ehcache.Element;
25  import net.sf.ehcache.distribution.CacheReplicator;
26  
27  /**
28   * <a href="EhcachePortalCacheClusterReplicator.java.html"><b><i>View Source</i>
29   * </b></a>
30   *
31   * @author Shuyang Zhou
32   */
33  public class EhcachePortalCacheClusterReplicator implements CacheReplicator {
34  
35      public boolean alive() {
36          return true;
37      }
38  
39      public Object clone() throws CloneNotSupportedException {
40          return super.clone();
41      }
42  
43      public void dispose() {
44      }
45  
46      public boolean isReplicateUpdatesViaCopy() {
47          return false;
48      }
49  
50      public boolean notAlive() {
51          return false;
52      }
53  
54      public void notifyElementEvicted(Ehcache ehcache, Element element) {
55          PortalCacheClusterLinkUtil.sendEvent(
56              new PortalCacheClusterEvent(
57                  ehcache.getName(), element.getKey(),
58                  PortalCacheClusterEventType.EVICTED));
59      }
60  
61      public void notifyElementExpired(Ehcache ehcache, Element element) {
62          PortalCacheClusterLinkUtil.sendEvent(
63              new PortalCacheClusterEvent(
64                  ehcache.getName(), element.getKey(),
65                  PortalCacheClusterEventType.EXPIRED));
66      }
67  
68      public void notifyElementPut(Ehcache ehcache, Element element)
69          throws CacheException {
70          PortalCacheClusterLinkUtil.sendEvent(
71              new PortalCacheClusterEvent(
72                  ehcache.getName(), element.getKey(),
73                  PortalCacheClusterEventType.PUT));
74      }
75  
76      public void notifyElementRemoved(Ehcache ehcache, Element element)
77          throws CacheException {
78          PortalCacheClusterLinkUtil.sendEvent(
79              new PortalCacheClusterEvent(
80                  ehcache.getName(), element.getKey(),
81                  PortalCacheClusterEventType.REMOVE));
82      }
83  
84      public void notifyElementUpdated(Ehcache ehcache, Element element)
85          throws CacheException {
86          PortalCacheClusterLinkUtil.sendEvent(
87              new PortalCacheClusterEvent(
88                  ehcache.getName(), element.getKey(),
89                  PortalCacheClusterEventType.UPDATE));
90      }
91  
92      public void notifyRemoveAll(Ehcache ehcache) {
93          PortalCacheClusterLinkUtil.sendEvent(
94              new PortalCacheClusterEvent(
95                  ehcache.getName(), StringPool.BLANK,
96                  PortalCacheClusterEventType.REMOVEALL));
97      }
98  
99  }