View Javadoc

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  
17  package net.sf.ehcache.hibernate.management.api;
18  
19  import java.util.Map;
20  
21  import javax.management.NotificationEmitter;
22  
23  /***
24   * Interface for ehcache related statistics of hibernate second level cache
25   * 
26   * <p />
27   * 
28   * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
29   * 
30   */
31  public interface EhcacheStats extends NotificationEmitter {
32      /***
33       * CACHE_ENABLED
34       */
35      public static final String CACHE_ENABLED = "CacheEnabled";
36      
37      /***
38       * CACHE_REGION_CHANGED
39       */
40      public static final String CACHE_REGION_CHANGED = "CacheRegionChanged";
41      
42      /***
43       * CACHE_FLUSHED
44       */
45      public static final String CACHE_FLUSHED = "CacheFlushed";
46      
47      /***
48       * CACHE_REGION_FLUSHED
49       */
50      public static final String CACHE_REGION_FLUSHED = "CacheRegionFlushed";
51      
52      /***
53       * CACHE_STATISTICS_ENABLED
54       */
55      public static final String CACHE_STATISTICS_ENABLED = "CacheStatisticsEnabled";
56      
57      /***
58       * CACHE_STATISTICS_RESET
59       */
60      public static final String CACHE_STATISTICS_RESET = "CacheStatisticsReset";
61  
62      /***
63       * Returns true if statistics collection is enabled
64       * 
65       * @return true if statistics collection is enabled
66       */
67      boolean isStatisticsEnabled();
68  
69      /***
70       * Enable/Disable statistics collection for all cache of the related session-factory
71       * 
72       * @param flag
73       */
74      void setStatisticsEnabled(boolean flag);
75  
76      /***
77       * Enables statistics collection
78       */
79      void enableStats();
80  
81      /***
82       * Disables statistics collection
83       */
84      void disableStats();
85  
86      /***
87       * Clears current statistics, resets all counters to zero
88       */
89      void clearStats();
90  
91      /***
92       * Get the original cache configuration
93       * 
94       * @return the original cache configuration
95       */
96      String getOriginalConfigDeclaration();
97  
98      /***
99       * Returns the original cache configuration for the supplied region
100      * 
101      * @param region
102      *            for which the configuration is required
103      * @return the original cache configuration for the supplied region
104      */
105     String getOriginalConfigDeclaration(String region);
106 
107     /***
108      * Returns the currently active cache configuration
109      * 
110      * @return the currently active cache configuration
111      */
112     String generateActiveConfigDeclaration();
113 
114     /***
115      * Returns the currently active cache configuration for the supplied region
116      * 
117      * @param region
118      * @return Returns the currently active cache configuration for the supplied region
119      */
120     String generateActiveConfigDeclaration(String region);
121 
122     /***
123      * Returns true if the input region is clustered with terracotta
124      * 
125      * @param region
126      * @return Returns true if the input region is clustered with terracotta
127      */
128     boolean isTerracottaHibernateCache(String region);
129 
130     /***
131      * Returns the region names which are clustered with terracotta
132      * 
133      * @return Returns the region names which are clustered with terracotta
134      */
135     String[] getTerracottaHibernateCacheRegionNames();
136 
137     /***
138      * Returns a map containing attributes of the cache for the input cache region name
139      * 
140      * @param regionName
141      * @return Returns a map containing attributes of the cache for the input cache region name
142      */
143     Map<String, Object> getRegionCacheAttributes(String regionName);
144 
145     /***
146      * Returns a map containing mapping of all cache region names to their attributes
147      * 
148      * @return Returns a map containing mapping of all cache region names to their attributes
149      */
150     Map<String, Map<String, Object>> getRegionCacheAttributes();
151 
152     /***
153      * Returns true if cache is enabled for the input region
154      * 
155      * @param region
156      * @return Returns true if cache is enabled for the input region
157      */
158     boolean isRegionCacheEnabled(String region);
159 
160     
161     /***
162      * Enables/disables a particular region
163      * 
164      * @param region
165      * @param enabled
166      */
167     void setRegionCacheEnabled(String region, boolean enabled);
168     
169     /***
170      * Returns true if all the cache regions are enabled. If even one cache is disabled, it will return false
171      * 
172      * @return Returns true if all the cache regions are enabled. If even one cache is disabled, it will return false
173      */
174     boolean isRegionCachesEnabled();
175 
176     /***
177      * Enable/disable all the cache regions.
178      */
179     void setRegionCachesEnabled(boolean enabled);
180     
181     /***
182      * Returns the time to idle for the input cache region
183      * 
184      * @param region
185      * @return Returns the time to live for the input cache region
186      */
187     int getRegionCacheMaxTTISeconds(String region);
188 
189     /***
190      * Sets the time to idle for the input cache region
191      * 
192      * @param region
193      * @param maxTTISeconds
194      *            Returns the time to idle for the input cache region
195      */
196     void setRegionCacheMaxTTISeconds(String region, int maxTTISeconds);
197 
198     /***
199      * Returns the time to live for the input cache region
200      * 
201      * @param region
202      * @return Returns the time to live for the input cache region
203      */
204     int getRegionCacheMaxTTLSeconds(String region);
205 
206     /***
207      * Sets the time to live for the input cache region
208      * 
209      * @param region
210      * @param maxTTLSeconds
211      */
212     void setRegionCacheMaxTTLSeconds(String region, int maxTTLSeconds);
213 
214     /***
215      * Returns the maxElementsInMemory of the input cache region
216      * 
217      * @param region
218      * @return Returns the maxElementsInMemory of the input cache region
219      */
220     int getRegionCacheTargetMaxInMemoryCount(String region);
221 
222     /***
223      * Sets the maxElementsInMemory of the input cache region
224      * 
225      * @param region
226      * @param targetMaxInMemoryCount
227      */
228     void setRegionCacheTargetMaxInMemoryCount(String region, int targetMaxInMemoryCount);
229 
230     /***
231      * Returns the maxElementsOnDisk of the input cache region
232      * 
233      * @param region
234      * @return Returns the maxElementsOnDisk of the input cache region
235      */
236     int getRegionCacheTargetMaxTotalCount(String region);
237 
238     /***
239      * Sets the maxElementsOnDisk of the input cache region
240      * 
241      * @param region
242      * @param targetMaxTotalCount
243      */
244     void setRegionCacheTargetMaxTotalCount(String region, int targetMaxTotalCount);
245 
246     /***
247      * Returns true if logging is enabled for the input cache region
248      * 
249      * @param region
250      * @return Returns true if logging is enabled for the input cache region
251      */
252     boolean isRegionCacheLoggingEnabled(String region);
253 
254     /***
255      * Enable/Disable logging for the input cache region
256      * 
257      * @param region
258      * @param loggingEnabled
259      */
260     void setRegionCacheLoggingEnabled(String region, boolean loggingEnabled);
261 
262     /***
263      * Returns true if orphan eviction is enabled for the region otherwise false
264      * 
265      * @param region
266      * @return Returns true if orphan eviction is enabled for the region otherwise false
267      */
268     boolean isRegionCacheOrphanEvictionEnabled(String region);
269 
270     /***
271      * Returns the orphan eviction period for the input cache region.
272      * 
273      * @param region
274      * @return Returns the orphan eviction period for the input cache region.
275      */
276     int getRegionCacheOrphanEvictionPeriod(String region);
277 
278     /***
279      * Flushes the cache for the input region
280      * 
281      * @param region
282      */
283     void flushRegionCache(String region);
284 
285     /***
286      * Flushes all the caches for all the regions
287      */
288     void flushRegionCaches();
289 
290     /***
291      * Returns hit count for all the caches
292      * 
293      * @return Returns hit count for all the caches
294      */
295     long getCacheHitCount();
296 
297     /***
298      * Returns hit count sample for all the caches
299      * 
300      * @return Returns hit count sample for all the caches
301      */
302     long getCacheHitSample();
303 
304     /***
305      * Returns hit rate for all the caches
306      * 
307      * @return Returns hit rate for all the caches
308      */
309     double getCacheHitRate();
310 
311     /***
312      * Returns miss count for all the caches
313      * 
314      * @return Returns miss count for all the caches
315      */
316     long getCacheMissCount();
317 
318     /***
319      * Returns miss count sample for all the caches
320      * 
321      * @return Returns miss count sample for all the caches
322      */
323     long getCacheMissSample();
324 
325     /***
326      * Returns miss rate for all the caches
327      * 
328      * @return Returns miss rate for all the caches
329      */
330     double getCacheMissRate();
331 
332     /***
333      * Returns put count sample for all the caches
334      * 
335      * @return Returns put count sample for all the caches
336      */
337     long getCachePutSample();
338 
339     /***
340      * Returns put count for all the caches
341      * 
342      * @return Returns put count for all the caches
343      */
344     long getCachePutCount();
345 
346     /***
347      * Returns put rate for all the caches
348      * 
349      * @return Returns put rate for all the caches
350      */
351     double getCachePutRate();
352 
353     /***
354      * Returns a map containing mapping between cache names and an array containing hit, miss and put count samples
355      * 
356      * @return Returns a map containing mapping between cache names and an array containing hit, miss and put count samples
357      */
358     Map<String, int[]> getRegionCacheSamples();
359 
360     /***
361      * Returns number of elements in-memory in the cache for the input region
362      * 
363      * @param region
364      * @return Returns number of elements in-memory in the cache for the input region
365      */
366     int getNumberOfElementsInMemory(String region);
367 
368     /***
369      * Returns number of elements off-heap in the cache for the input region
370      *
371      * @param region
372      * @return Returns number of elements off-heap in the cache for the input region
373      */
374     int getNumberOfElementsOffHeap(String region);
375 
376     /***
377      * Returns number of elements on-disk in the cache for the input region
378      * 
379      * @param region
380      * @return Returns number of elements on-disk in the cache for the input region
381      */
382     int getNumberOfElementsOnDisk(String region);
383 
384     /***
385      * Return minimum time taken for a get operation in the cache in milliseconds
386      * 
387      * @return minimum time taken for a get operation in the cache in milliseconds
388      */
389     public long getMinGetTimeMillis();
390 
391     /***
392      * Return maximum time taken in milliseconds for a get operation
393      * 
394      * @return Return maximum time taken in milliseconds for a get operation
395      */
396     public long getMaxGetTimeMillis();
397 
398     /***
399      * Return average time taken in milliseconds for a get operation for the input cache name
400      * 
401      * @return Return average time taken in milliseconds for a get operation for the input cache name
402      */
403     public float getAverageGetTimeMillis(String region);
404 
405     /***
406      * Return minimum time taken in milliseconds for a get operation for the input cache name
407      * 
408      * @return Return minimum time taken in milliseconds for a get operation for the input cache name
409      */
410     public long getMinGetTimeMillis(String cacheName);
411 
412     /***
413      * Return maximum time taken in milliseconds for a get operation for the input cache name
414      * 
415      * @return Return maximum time taken in milliseconds for a get operation for the input cache name
416      */
417     public long getMaxGetTimeMillis(String cacheName);
418 
419 }