1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }