1 /**
2 * Copyright 2003-2007 Greg Luck
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.event;
18
19 import net.sf.ehcache.CacheException;
20 import net.sf.ehcache.Ehcache;
21 import net.sf.ehcache.Element;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /**
26 * A Null Object Pattern implementation of CacheEventListener. It simply logs the calls made.
27 * @author Greg Luck
28 * @version $Id: NullCacheEventListener.java 512 2007-07-10 09:18:45Z gregluck $
29 * @since 1.2
30 */
31 public class NullCacheEventListener implements CacheEventListener {
32
33 private static final Log LOG = LogFactory.getLog(NullCacheEventListener.class.getName());
34
35
36 /**
37 * {@inheritDoc}
38 */
39 public void notifyElementRemoved(final Ehcache cache, final Element element) {
40 if (LOG.isTraceEnabled()) {
41 LOG.trace("notifyElementRemoved called for cache " + cache + " for element with key " + element.getObjectKey());
42 }
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 public void notifyElementPut(final Ehcache cache, final Element element) {
49 if (LOG.isTraceEnabled()) {
50 Object key = null;
51 if (element != null) {
52 key = element.getObjectKey();
53 }
54 LOG.trace("notifyElementPut called for cache " + cache + " for element with key " + key);
55 }
56 }
57
58 /**
59 * Called immediately after an element has been put into the cache and the element already
60 * existed in the cache. This is thus an update.
61 * <p/>
62 * The {@link net.sf.ehcache.Cache#put(net.sf.ehcache.Element)} method
63 * will block until this method returns.
64 * <p/>
65 * Implementers may wish to have access to the Element's fields, including value, so the element is provided.
66 * Implementers should be careful not to modify the element. The effect of any modifications is undefined.
67 *
68 * @param cache the cache emitting the notification
69 * @param element the element which was just put into the cache.
70 */
71 public void notifyElementUpdated(final Ehcache cache, final Element element) throws CacheException {
72 if (LOG.isTraceEnabled()) {
73 Object key = null;
74 if (element != null) {
75 key = element.getObjectKey();
76 }
77 LOG.trace("notifyElementUpdated called for cache " + cache + " for element with key " + key);
78 }
79 }
80
81 /**
82 * {@inheritDoc}
83 */
84 public void notifyElementExpired(final Ehcache cache, final Element element) {
85 if (LOG.isTraceEnabled()) {
86 LOG.trace("notifyElementExpired called for cache " + cache + " for element with key " + element.getObjectKey());
87 }
88 }
89
90 /**
91 * {@inheritDoc}
92 */
93 public void notifyElementEvicted(final Ehcache cache, final Element element) {
94 //
95 }
96
97 /**
98 * {@inheritDoc}
99 */
100 public void notifyRemoveAll(final Ehcache cache) {
101 //
102 }
103
104 /**
105 * Give the replicator a chance to cleanup and free resources when no longer needed
106 */
107 public void dispose() {
108 //nothing to do
109 }
110
111 /**
112 * Creates a clone of this listener. This method will only be called by ehcache before a cache is initialized.
113 * <p/>
114 * This may not be possible for listeners after they have been initialized. Implementations should throw
115 * CloneNotSupportedException if they do not support clone.
116 * @return a clone
117 * @throws CloneNotSupportedException if the listener could not be cloned.
118 */
119 public Object clone() throws CloneNotSupportedException {
120 return super.clone();
121 }
122 }