1 /**
2 * Copyright 2003-2006 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.Cache;
20 import net.sf.ehcache.CacheException;
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 * <p/>
28 * It is used by default.
29 *
30 * @author Greg Luck
31 * @version $Id: NullCacheEventListener.java 44 2006-04-22 06:03:33Z gregluck $
32 * @since 1.2
33 */
34 public class NullCacheEventListener implements CacheEventListener {
35
36 private static final Log LOG = LogFactory.getLog(NullCacheEventListener.class.getName());
37
38
39 /**
40 * {@inheritDoc}
41 */
42 public void notifyElementRemoved(final Cache cache, final Element element) {
43 if (LOG.isTraceEnabled()) {
44 LOG.trace("notifyElementRemoved called for cache " + cache + " for element with key " + element.getObjectKey());
45 }
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 public void notifyElementPut(final Cache cache, final Element element) {
52 if (LOG.isTraceEnabled()) {
53 Object key = null;
54 if (element != null) {
55 key = element.getObjectKey();
56 }
57 LOG.trace("notifyElementPut called for cache " + cache + " for element with key " + key);
58 }
59 }
60
61 /**
62 * Called immediately after an element has been put into the cache and the element already
63 * existed in the cache. This is thus an update.
64 * <p/>
65 * The {@link net.sf.ehcache.Cache#put(net.sf.ehcache.Element)} method
66 * will block until this method returns.
67 * <p/>
68 * Implementers may wish to have access to the Element's fields, including value, so the element is provided.
69 * Implementers should be careful not to modify the element. The effect of any modifications is undefined.
70 *
71 * @param cache the cache emitting the notification
72 * @param element the element which was just put into the cache.
73 */
74 public void notifyElementUpdated(final Cache cache, final Element element) throws CacheException {
75 if (LOG.isTraceEnabled()) {
76 Object key = null;
77 if (element != null) {
78 key = element.getObjectKey();
79 }
80 LOG.trace("notifyElementUpdated called for cache " + cache + " for element with key " + key);
81 }
82 }
83
84 /**
85 * {@inheritDoc}
86 */
87 public void notifyElementExpired(final Cache cache, final Element element) {
88 if (LOG.isTraceEnabled()) {
89 LOG.trace("notifyElementExpired called for cache " + cache + " for element with key " + element.getObjectKey());
90 }
91 }
92
93 /**
94 * Give the replicator a chance to cleanup and free resources when no longer needed
95 */
96 public void dispose() {
97
98 }
99 }