1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
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 package net.sf.ehcache.statistics;
17
18 /***
19 * Interface for listeners to any change in usage statistics of an
20 * Ehcache.
21 *
22 * <p />
23 * Implementations of this interface should implement the {@link Object#equals(Object)} and the {@link Object#hashCode()} as registering and
24 * removing listeners depends on these
25 * <p />
26 *
27 * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
28 * @since 1.7
29 */
30 public interface CacheUsageListener {
31
32 /***
33 * Called when statistics is enabled/disabled
34 *
35 * @param enableStatistics
36 */
37 void notifyStatisticsEnabledChanged(boolean enableStatistics);
38
39 /***
40 * Called when statistics is cleared
41 */
42 void notifyStatisticsCleared();
43
44 /***
45 * Called on a cache hit in the MemoryStore
46 */
47 void notifyCacheHitInMemory();
48
49 /***
50 * Called on a cache hit in the off-heap store
51 */
52 void notifyCacheHitOffHeap();
53
54 /***
55 * Called on a cache hit in the DiskStore
56 */
57 void notifyCacheHitOnDisk();
58
59 /***
60 * Called when an element is inserted in the cache
61 */
62 void notifyCacheElementPut();
63
64 /***
65 * Called when an element is updated in the cache, i.e. a put for an already
66 * existing key
67 */
68 void notifyCacheElementUpdated();
69
70 /***
71 * Called when an element is not found in the cache
72 */
73 void notifyCacheMissedWithNotFound();
74
75 /***
76 * Called on a cache miss in the MemoryStore
77 */
78 void notifyCacheMissInMemory();
79
80 /***
81 * Called on a cache miss in the off-heap store
82 */
83 void notifyCacheMissOffHeap();
84
85 /***
86 * Called on a cache miss in the DiskStore
87 */
88 void notifyCacheMissOnDisk();
89
90 /***
91 * Called when an element is found in the cache but already expired
92 */
93 void notifyCacheMissedWithExpired();
94
95 /***
96 * Notified with time taken for a get operation in the cache
97 *
98 * @param millis
99 */
100 void notifyTimeTakenForGet(final long millis);
101
102 /***
103 * Called when an element is expired in the cache
104 */
105 void notifyCacheElementEvicted();
106
107 /***
108 * Called when an element in the cache expires
109 */
110 void notifyCacheElementExpired();
111
112 /***
113 * Called when an element is removed from the cache
114 */
115 void notifyCacheElementRemoved();
116
117 /***
118 * Called when Cache.removeAll() is called
119 */
120 void notifyRemoveAll();
121
122 /***
123 * Notified when the statistics accuracy is changed.
124 *
125 * @param statisticsAccuracy
126 * one of Statistics#STATISTICS_ACCURACY_BEST_EFFORT,
127 * Statistics#STATISTICS_ACCURACY_GUARANTEED,
128 * Statistics#STATISTICS_ACCURACY_NONE
129 */
130 void notifyStatisticsAccuracyChanged(int statisticsAccuracy);
131
132 /***
133 * Called to dispose off the listener
134 */
135 void dispose();
136
137 /***
138 * Called when a search finishes execution
139 *
140 * @param executeTime elapsed time in millis
141 */
142 void notifyCacheSearch(long executeTime);
143
144 /***
145 * Called when the Cache's XAResource has been asked to commit
146 */
147 void notifyXaCommit();
148
149 /***
150 * Called when the Cache's XAResource has been asked to rollback
151 */
152 void notifyXaRollback();
153
154 }