001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.oscache.extra;
006:
007: import com.opensymphony.oscache.base.events.*;
008:
009: /**
010: * Implementation of a CacheEntryEventListener. It use the events to count
011: * the operations performed on the cache.
012: * <p>
013: * We are not using any synchronized so that this does not become a bottleneck.
014: * The consequence is that on retrieving values, the operations that are
015: * currently being done won't be counted.
016: *
017: * @version $Revision: 254 $
018: * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
019: * @author <a href="mailto:chris@swebtec.com">Chris Miller</a>
020: */
021: public class CacheEntryEventListenerImpl implements
022: CacheEntryEventListener {
023: /**
024: * Counter for the cache flushes
025: */
026: private int cacheFlushedCount = 0;
027:
028: /**
029: * Counter for the added entries
030: */
031: private int entryAddedCount = 0;
032:
033: /**
034: * Counter for the flushed entries
035: */
036: private int entryFlushedCount = 0;
037:
038: /**
039: * Counter for the removed entries
040: */
041: private int entryRemovedCount = 0;
042:
043: /**
044: * Counter for the updated entries
045: */
046: private int entryUpdatedCount = 0;
047:
048: /**
049: * Counter for the flushed groups
050: */
051: private int groupFlushedCount = 0;
052:
053: /**
054: * Counter for the pattern flushes
055: */
056: private int patternFlushedCount = 0;
057:
058: /**
059: * Constructor, empty for us
060: */
061: public CacheEntryEventListenerImpl() {
062: }
063:
064: /**
065: * Gets the add counter
066: *
067: * @return The added counter
068: */
069: public int getEntryAddedCount() {
070: return entryAddedCount;
071: }
072:
073: /**
074: * Gets the flushed counter
075: *
076: * @return The flushed counter
077: */
078: public int getEntryFlushedCount() {
079: return entryFlushedCount;
080: }
081:
082: /**
083: * Gets the removed counter
084: *
085: * @return The removed counter
086: */
087: public int getEntryRemovedCount() {
088: return entryRemovedCount;
089: }
090:
091: /**
092: * Gets the updated counter
093: *
094: * @return The updated counter
095: */
096: public int getEntryUpdatedCount() {
097: return entryUpdatedCount;
098: }
099:
100: /**
101: * Gets the group flush counter
102: *
103: * @return The number of group flush calls that have occurred
104: */
105: public int getGroupFlushedCount() {
106: return groupFlushedCount;
107: }
108:
109: /**
110: * Gets the pattern flush counter
111: *
112: * @return The number of pattern flush calls that have occurred
113: */
114: public int getPatternFlushedCount() {
115: return patternFlushedCount;
116: }
117:
118: /**
119: * Gets the cache flush counter
120: *
121: * @return The number of times the entire cache has been flushed
122: */
123: public int getCacheFlushedCount() {
124: return cacheFlushedCount;
125: }
126:
127: /**
128: * Handles the event fired when an entry is added in the cache.
129: *
130: * @param event The event triggered when a cache entry has been added
131: */
132: public void cacheEntryAdded(CacheEntryEvent event) {
133: entryAddedCount++;
134: }
135:
136: /**
137: * Handles the event fired when an entry is flushed from the cache.
138: *
139: * @param event The event triggered when a cache entry has been flushed
140: */
141: public void cacheEntryFlushed(CacheEntryEvent event) {
142: entryFlushedCount++;
143: }
144:
145: /**
146: * Handles the event fired when an entry is removed from the cache.
147: *
148: * @param event The event triggered when a cache entry has been removed
149: */
150: public void cacheEntryRemoved(CacheEntryEvent event) {
151: entryRemovedCount++;
152: }
153:
154: /**
155: * Handles the event fired when an entry is updated in the cache.
156: *
157: * @param event The event triggered when a cache entry has been updated
158: */
159: public void cacheEntryUpdated(CacheEntryEvent event) {
160: entryUpdatedCount++;
161: }
162:
163: /**
164: * Handles the event fired when a group is flushed from the cache.
165: *
166: * @param event The event triggered when a cache group has been flushed
167: */
168: public void cacheGroupFlushed(CacheGroupEvent event) {
169: groupFlushedCount++;
170: }
171:
172: /**
173: * Handles the event fired when a pattern is flushed from the cache.
174: *
175: * @param event The event triggered when a cache pattern has been flushed
176: */
177: public void cachePatternFlushed(CachePatternEvent event) {
178: patternFlushedCount++;
179: }
180:
181: /**
182: * Handles the event fired when a cache flush occurs.
183: *
184: * @param event The event triggered when an entire cache is flushed
185: */
186: public void cacheFlushed(CachewideEvent event) {
187: cacheFlushedCount++;
188: }
189:
190: /**
191: * Returns the internal values in a string form
192: */
193: public String toString() {
194: return ("Added " + entryAddedCount + ", Updated "
195: + entryUpdatedCount + ", Flushed " + entryFlushedCount
196: + ", Removed " + entryRemovedCount
197: + ", Groups Flushed " + groupFlushedCount
198: + ", Patterns Flushed " + patternFlushedCount
199: + ", Cache Flushed " + cacheFlushedCount);
200: }
201: }
|