~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/management/sampled/SampledCacheManager.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 *  Copyright 2003-2010 Terracotta, Inc.
 
2
 *  Copyright Terracotta, Inc.
3
3
 *
4
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
5
 *  you may not use this file except in compliance with the License.
16
16
 
17
17
package net.sf.ehcache.management.sampled;
18
18
 
 
19
import net.sf.ehcache.CacheException;
 
20
import net.sf.ehcache.CacheManager;
 
21
import net.sf.ehcache.hibernate.management.impl.BaseEmitterBean;
 
22
 
19
23
import java.util.HashMap;
20
24
import java.util.Map;
21
25
 
23
27
import javax.management.NotCompliantMBeanException;
24
28
import javax.management.Notification;
25
29
 
26
 
import net.sf.ehcache.Cache;
27
 
import net.sf.ehcache.CacheException;
28
 
import net.sf.ehcache.CacheManager;
29
 
import net.sf.ehcache.Ehcache;
30
 
import net.sf.ehcache.Status;
31
 
import net.sf.ehcache.config.CacheWriterConfiguration;
32
 
import net.sf.ehcache.event.CacheManagerEventListener;
33
 
import net.sf.ehcache.hibernate.management.impl.BaseEmitterBean;
34
 
import net.sf.ehcache.statistics.LiveCacheStatistics;
35
 
import net.sf.ehcache.statistics.sampled.SampledCacheStatistics;
36
 
import net.sf.ehcache.writer.writebehind.WriteBehindManager;
37
 
 
38
30
/**
39
31
 * An implementation of {@link SampledCacheManagerMBean}
40
32
 *
41
 
 * <p />
42
 
 *
43
33
 * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
44
 
 * @since 1.7
 
34
 * @author <a href="mailto:byoukste@terracottatech.com">byoukste</a>
45
35
 */
46
36
public class SampledCacheManager extends BaseEmitterBean implements SampledCacheManagerMBean {
47
37
    private static final MBeanNotificationInfo[] NOTIFICATION_INFO;
48
38
 
49
 
    private final CacheManager cacheManager;
 
39
    private final CacheManagerSampler sampledCacheManagerDelegate;
50
40
    private String mbeanRegisteredName;
51
41
    private volatile boolean mbeanRegisteredNameSet;
52
 
    private final EventListener cacheManagerEventListener;
53
42
 
54
43
    static {
55
 
        final String[] notifTypes = new String[] {CACHES_ENABLED, CACHES_CLEARED, STATISTICS_ENABLED, STATISTICS_RESET, };
 
44
        final String[] notifTypes = new String[] {CACHES_ENABLED, CACHES_CLEARED, STATISTICS_ENABLED, STATISTICS_RESET};
56
45
        final String name = Notification.class.getName();
57
46
        final String description = "Ehcache SampledCacheManager Event";
58
 
        NOTIFICATION_INFO = new MBeanNotificationInfo[] {new MBeanNotificationInfo(notifTypes, name, description), };
 
47
        NOTIFICATION_INFO = new MBeanNotificationInfo[] {new MBeanNotificationInfo(notifTypes, name, description)};
59
48
    }
60
49
 
61
50
    /**
62
51
     * Constructor taking the backing {@link CacheManager}
63
52
     *
64
 
     * @param cacheManager
 
53
     * @param cacheManager the cacheManager to wrap
 
54
     * @throws javax.management.NotCompliantMBeanException
 
55
     *          if invalid object is registered
65
56
     */
66
57
    public SampledCacheManager(CacheManager cacheManager) throws NotCompliantMBeanException {
67
58
        super(SampledCacheManagerMBean.class);
68
 
        this.cacheManager = cacheManager;
69
 
        cacheManagerEventListener = new EventListener();
70
 
        cacheManager.setCacheManagerEventListener(cacheManagerEventListener);
 
59
        sampledCacheManagerDelegate = new CacheManagerSamplerImpl(cacheManager);
71
60
    }
72
61
 
73
62
    /**
75
64
     */
76
65
    @Override
77
66
    protected void doDispose() {
78
 
        cacheManager.getCacheManagerEventListenerRegistry().unregisterListener(cacheManagerEventListener);
79
 
    }
80
 
 
81
 
    /**
82
 
     * Listen for caches coming and going so that we can add a PropertyChangeListener.
83
 
     */
84
 
    private static class EventListener implements CacheManagerEventListener {
85
 
        private Status status = Status.STATUS_UNINITIALISED;
86
 
 
87
 
        public void dispose() throws CacheException {
88
 
            status = Status.STATUS_SHUTDOWN;
89
 
        }
90
 
 
91
 
        public Status getStatus() {
92
 
            return status;
93
 
        }
94
 
 
95
 
        public void init() throws CacheException {
96
 
            status = Status.STATUS_ALIVE;
97
 
        }
98
 
 
99
 
        public void notifyCacheAdded(String cacheName) {
100
 
            /**/
101
 
        }
102
 
 
103
 
        public void notifyCacheRemoved(String cacheName) {
104
 
            /**/
105
 
        }
 
67
 
106
68
    }
107
69
 
108
70
    /**
109
71
     * Set the name used to register this mbean. Can be called only once.
110
72
     * Package protected method
 
73
     *
 
74
     * @param name the MBean name to be registered.
111
75
     */
112
76
    void setMBeanRegisteredName(String name) {
113
77
        if (mbeanRegisteredNameSet) {
121
85
     * {@inheritDoc}
122
86
     */
123
87
    public void clearAll() {
124
 
        cacheManager.clearAll();
 
88
        sampledCacheManagerDelegate.clearAll();
125
89
        sendNotification(CACHES_CLEARED);
126
90
    }
127
91
 
129
93
     * {@inheritDoc}
130
94
     */
131
95
    public String[] getCacheNames() throws IllegalStateException {
132
 
        return cacheManager.getCacheNames();
 
96
        return sampledCacheManagerDelegate.getCacheNames();
133
97
    }
134
98
 
135
99
    /**
136
100
     * {@inheritDoc}
137
101
     */
138
102
    public String getStatus() {
139
 
        return cacheManager.getStatus().toString();
 
103
        return sampledCacheManagerDelegate.getStatus();
140
104
    }
141
105
 
142
106
    /**
150
114
     * @return map of cache metrics (hits, misses)
151
115
     */
152
116
    public Map<String, long[]> getCacheMetrics() {
153
 
        Map<String, long[]> result = new HashMap<String, long[]>();
154
 
        for (String cacheName : getCacheNames()) {
155
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
156
 
            if (cache != null) {
157
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
158
 
                result.put(cacheName, new long[] {stats.getCacheHitMostRecentSample(),
159
 
                        stats.getCacheMissNotFoundMostRecentSample()
160
 
                        + stats.getCacheMissExpiredMostRecentSample(),
161
 
                        stats.getCacheElementPutMostRecentSample(), });
162
 
            }
163
 
        }
164
 
        return result;
 
117
        return sampledCacheManagerDelegate.getCacheMetrics();
165
118
    }
166
119
 
167
120
    /**
168
121
     * @return aggregate hit rate
169
122
     */
170
123
    public long getCacheHitRate() {
171
 
        long result = 0;
172
 
        for (String cacheName : getCacheNames()) {
173
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
174
 
            if (cache != null) {
175
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
176
 
                result += stats.getCacheHitMostRecentSample();
177
 
            }
178
 
        }
179
 
        return result;
 
124
        return sampledCacheManagerDelegate.getCacheHitRate();
180
125
    }
181
126
 
182
127
    /**
183
128
     * @return aggregate in-memory hit rate
184
129
     */
185
130
    public long getCacheInMemoryHitRate() {
186
 
        long result = 0;
187
 
        for (String cacheName : getCacheNames()) {
188
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
189
 
            if (cache != null) {
190
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
191
 
                result += stats.getCacheHitInMemoryMostRecentSample();
192
 
            }
193
 
        }
194
 
        return result;
 
131
        return sampledCacheManagerDelegate.getCacheInMemoryHitRate();
195
132
    }
196
133
 
197
134
    /**
198
135
     * @return aggregate off-heap hit rate
199
136
     */
200
137
    public long getCacheOffHeapHitRate() {
201
 
        long result = 0;
202
 
        for (String cacheName : getCacheNames()) {
203
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
204
 
            if (cache != null) {
205
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
206
 
                result += stats.getCacheHitOffHeapMostRecentSample();
207
 
            }
208
 
        }
209
 
        return result;
 
138
        return sampledCacheManagerDelegate.getCacheOffHeapHitRate();
210
139
    }
211
140
 
212
141
    /**
213
142
     * @return aggregate on-disk hit rate
214
143
     */
215
144
    public long getCacheOnDiskHitRate() {
216
 
        long result = 0;
217
 
        for (String cacheName : getCacheNames()) {
218
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
219
 
            if (cache != null) {
220
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
221
 
                result += stats.getCacheHitOnDiskMostRecentSample();
222
 
            }
223
 
        }
224
 
        return result;
 
145
        return sampledCacheManagerDelegate.getCacheOnDiskHitRate();
225
146
    }
226
147
 
227
148
    /**
228
149
     * @return aggregate miss rate
229
150
     */
230
151
    public long getCacheMissRate() {
231
 
        long result = 0;
232
 
        for (String cacheName : getCacheNames()) {
233
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
234
 
            if (cache != null) {
235
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
236
 
                result += (stats.getCacheMissNotFoundMostRecentSample()
237
 
                    + stats.getCacheMissExpiredMostRecentSample());
238
 
            }
239
 
        }
240
 
        return result;
 
152
        return sampledCacheManagerDelegate.getCacheMissRate();
241
153
    }
242
154
 
243
155
    /**
244
156
     * @return aggregate in-memory miss rate
245
157
     */
246
158
    public long getCacheInMemoryMissRate() {
247
 
        long result = 0;
248
 
        for (String cacheName : getCacheNames()) {
249
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
250
 
            if (cache != null) {
251
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
252
 
                result += stats.getCacheMissInMemoryMostRecentSample();
253
 
            }
254
 
        }
255
 
        return result;
 
159
        return sampledCacheManagerDelegate.getCacheInMemoryMissRate();
256
160
    }
257
161
 
258
162
    /**
259
163
     * @return aggregate off-heap miss rate
260
164
     */
261
165
    public long getCacheOffHeapMissRate() {
262
 
        long result = 0;
263
 
        for (String cacheName : getCacheNames()) {
264
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
265
 
            if (cache != null) {
266
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
267
 
                result += stats.getCacheMissOffHeapMostRecentSample();
268
 
            }
269
 
        }
270
 
        return result;
 
166
        return sampledCacheManagerDelegate.getCacheOffHeapMissRate();
271
167
    }
272
168
 
273
169
    /**
274
170
     * @return aggregate on-disk miss rate
275
171
     */
276
172
    public long getCacheOnDiskMissRate() {
277
 
        long result = 0;
278
 
        for (String cacheName : getCacheNames()) {
279
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
280
 
            if (cache != null) {
281
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
282
 
                result += stats.getCacheMissOnDiskMostRecentSample();
283
 
            }
284
 
        }
285
 
        return result;
 
173
        return sampledCacheManagerDelegate.getCacheOnDiskMissRate();
286
174
    }
287
175
 
288
176
    /**
289
177
     * @return aggregate put rate
290
178
     */
291
179
    public long getCachePutRate() {
292
 
        long result = 0;
293
 
        for (String cacheName : getCacheNames()) {
294
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
295
 
            if (cache != null) {
296
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
297
 
                result += stats.getCacheElementPutMostRecentSample();
298
 
            }
299
 
        }
300
 
        return result;
 
180
        return sampledCacheManagerDelegate.getCachePutRate();
301
181
    }
302
182
 
303
183
    /**
304
184
     * @return aggregate update rate
305
185
     */
306
186
    public long getCacheUpdateRate() {
307
 
        long result = 0;
308
 
        for (String cacheName : getCacheNames()) {
309
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
310
 
            if (cache != null) {
311
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
312
 
                result += stats.getCacheElementUpdatedMostRecentSample();
313
 
            }
314
 
        }
315
 
        return result;
 
187
        return sampledCacheManagerDelegate.getCacheUpdateRate();
316
188
    }
317
189
 
318
190
    /**
319
191
     * @return aggregate remove rate
320
192
     */
321
193
    public long getCacheRemoveRate() {
322
 
        long result = 0;
323
 
        for (String cacheName : getCacheNames()) {
324
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
325
 
            if (cache != null) {
326
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
327
 
                result += stats.getCacheElementRemovedMostRecentSample();
328
 
            }
329
 
        }
330
 
        return result;
 
194
        return sampledCacheManagerDelegate.getCacheRemoveRate();
331
195
    }
332
196
 
333
197
    /**
334
198
     * @return aggregate eviction rate
335
199
     */
336
200
    public long getCacheEvictionRate() {
337
 
        long result = 0;
338
 
        for (String cacheName : getCacheNames()) {
339
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
340
 
            if (cache != null) {
341
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
342
 
                result += stats.getCacheElementEvictedMostRecentSample();
343
 
            }
344
 
        }
345
 
        return result;
 
201
        return sampledCacheManagerDelegate.getCacheEvictionRate();
346
202
    }
347
203
 
348
204
    /**
349
205
     * @return aggregate expiration rate
350
206
     */
351
207
    public long getCacheExpirationRate() {
352
 
        long result = 0;
353
 
        for (String cacheName : getCacheNames()) {
354
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
355
 
            if (cache != null) {
356
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
357
 
                result += stats.getCacheElementExpiredMostRecentSample();
358
 
            }
359
 
        }
360
 
        return result;
 
208
        return sampledCacheManagerDelegate.getCacheExpirationRate();
361
209
    }
362
210
 
363
211
    /**
364
212
     * @return aggregate average get time (ms.)
365
213
     */
366
214
    public float getCacheAverageGetTime() {
367
 
        float result = 0;
368
 
        int instances = 0;
369
 
        for (String cacheName : getCacheNames()) {
370
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
371
 
            if (cache != null) {
372
 
                result += cache.getAverageGetTime();
373
 
                instances++;
374
 
            }
375
 
        }
376
 
        return instances > 0 ? result / instances : 0;
 
215
        return sampledCacheManagerDelegate.getCacheAverageGetTime();
377
216
    }
378
217
 
379
218
    /**
380
219
     * @return aggregate search rate
381
220
     */
382
221
    public long getCacheSearchRate() {
383
 
        long result = 0;
384
 
        for (String cacheName : getCacheNames()) {
385
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
386
 
            if (cache != null) {
387
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
388
 
                result += stats.getSearchesPerSecond();
389
 
            }
390
 
        }
391
 
        return result;
 
222
        return sampledCacheManagerDelegate.getCacheSearchRate();
392
223
    }
393
224
 
394
225
    /**
395
226
     * @return aggregate search time
396
227
     */
397
228
    public long getCacheAverageSearchTime() {
398
 
        long result = 0;
399
 
        for (String cacheName : getCacheNames()) {
400
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
401
 
            if (cache != null) {
402
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
403
 
                result += stats.getAverageSearchTime();
404
 
            }
405
 
        }
406
 
        return result;
 
229
        return sampledCacheManagerDelegate.getCacheAverageSearchTime();
407
230
    }
408
231
 
409
232
    /**
410
233
     * {@inheritDoc}
411
234
     */
412
235
    public boolean getHasWriteBehindWriter() {
413
 
        for (String cacheName : getCacheNames()) {
414
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
415
 
            if (cache != null) {
416
 
                if (cache.getWriterManager() instanceof WriteBehindManager &&
417
 
                        cache.getRegisteredCacheWriter() != null) {
418
 
                    return true;
419
 
                }
420
 
            }
421
 
        }
422
 
        return false;
 
236
        return sampledCacheManagerDelegate.getHasWriteBehindWriter();
423
237
    }
424
238
 
425
239
    /**
426
240
     * @return aggregate writer queue length
427
241
     */
428
242
    public long getWriterQueueLength() {
429
 
        long result = 0;
430
 
        for (String cacheName : getCacheNames()) {
431
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
432
 
            if (cache != null) {
433
 
                LiveCacheStatistics stats = cache.getLiveCacheStatistics();
434
 
                result += Math.max(stats.getWriterQueueLength(), 0);
435
 
            }
436
 
        }
437
 
        return result;
 
243
        return sampledCacheManagerDelegate.getWriterQueueLength();
438
244
    }
439
245
 
440
246
    /**
441
247
     * {@inheritDoc}
442
248
     */
443
249
    public int getWriterMaxQueueSize() {
444
 
        int result = 0;
445
 
        for (String cacheName : getCacheNames()) {
446
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
447
 
            if (cache != null) {
448
 
                CacheWriterConfiguration writerConfig = cache.getCacheConfiguration().getCacheWriterConfiguration();
449
 
                result += (writerConfig.getWriteBehindMaxQueueSize() * writerConfig.getWriteBehindConcurrency());
450
 
            }
451
 
        }
452
 
        return result;
 
250
        return sampledCacheManagerDelegate.getWriterMaxQueueSize();
453
251
    }
454
252
 
455
253
    /**
456
254
     * {@inheritDoc}
457
255
     */
458
256
    public long getMaxBytesLocalDisk() {
459
 
        return cacheManager.getConfiguration().getMaxBytesLocalDisk();
 
257
        return sampledCacheManagerDelegate.getMaxBytesLocalDisk();
460
258
    }
461
259
 
462
260
    /**
463
261
     * {@inheritDoc}
464
262
     */
465
263
    public String getMaxBytesLocalDiskAsString() {
466
 
        return cacheManager.getConfiguration().getMaxBytesLocalDiskAsString();
 
264
        return sampledCacheManagerDelegate.getMaxBytesLocalDiskAsString();
467
265
    }
468
266
 
469
267
    /**
470
268
     * {@inheritDoc}
471
269
     */
472
270
    public void setMaxBytesLocalDisk(long maxBytes) {
473
 
        try {
474
 
            cacheManager.getConfiguration().setMaxBytesLocalDisk(maxBytes);
475
 
            sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
476
 
        } catch (RuntimeException e) {
477
 
            throw SampledCache.newPlainException(e);
478
 
        }
 
271
        sampledCacheManagerDelegate.setMaxBytesLocalDisk(maxBytes);
 
272
        sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
479
273
    }
480
274
 
481
275
    /**
482
276
     * {@inheritDoc}
483
277
     */
484
278
    public void setMaxBytesLocalDiskAsString(String maxBytes) {
485
 
        try {
486
 
            cacheManager.getConfiguration().setMaxBytesLocalDisk(maxBytes);
487
 
            sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
488
 
        } catch (RuntimeException e) {
489
 
            throw SampledCache.newPlainException(e);
490
 
        }
 
279
        sampledCacheManagerDelegate.setMaxBytesLocalDiskAsString(maxBytes);
 
280
        sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
491
281
    }
492
282
 
493
283
    /**
494
284
     * {@inheritDoc}
495
285
     */
496
286
    public long getMaxBytesLocalHeap() {
497
 
        return cacheManager.getConfiguration().getMaxBytesLocalHeap();
 
287
        return sampledCacheManagerDelegate.getMaxBytesLocalHeap();
498
288
    }
499
289
 
500
290
    /**
501
291
     * {@inheritDoc}
502
292
     */
503
293
    public String getMaxBytesLocalHeapAsString() {
504
 
        return cacheManager.getConfiguration().getMaxBytesLocalHeapAsString();
 
294
        return sampledCacheManagerDelegate.getMaxBytesLocalHeapAsString();
505
295
    }
506
296
 
507
297
    /**
508
298
     * {@inheritDoc}
509
299
     */
510
300
    public void setMaxBytesLocalHeap(long maxBytes) {
511
 
        try {
512
 
            cacheManager.getConfiguration().setMaxBytesLocalHeap(maxBytes);
513
 
            sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
514
 
        } catch (RuntimeException e) {
515
 
            throw SampledCache.newPlainException(e);
516
 
        }
 
301
        sampledCacheManagerDelegate.setMaxBytesLocalHeap(maxBytes);
 
302
        sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
517
303
    }
518
304
 
519
305
    /**
520
306
     * {@inheritDoc}
521
307
     */
522
308
    public void setMaxBytesLocalHeapAsString(String maxBytes) {
523
 
        try {
524
 
            cacheManager.getConfiguration().setMaxBytesLocalHeap(maxBytes);
525
 
            sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
526
 
        } catch (RuntimeException e) {
527
 
            throw SampledCache.newPlainException(e);
528
 
        }
 
309
        sampledCacheManagerDelegate.setMaxBytesLocalHeapAsString(maxBytes);
 
310
        sendNotification(CACHE_MANAGER_CHANGED, getCacheManagerAttributes(), getName());
529
311
    }
530
312
 
531
313
    /**
532
314
     * {@inheritDoc}
533
315
     */
534
316
    public long getMaxBytesLocalOffHeap() {
535
 
        return cacheManager.getConfiguration().getMaxBytesLocalOffHeap();
 
317
        return sampledCacheManagerDelegate.getMaxBytesLocalOffHeap();
536
318
    }
537
319
 
538
320
    /**
539
321
     * {@inheritDoc}
540
322
     */
541
323
    public String getMaxBytesLocalOffHeapAsString() {
542
 
        return cacheManager.getConfiguration().getMaxBytesLocalOffHeapAsString();
 
324
        return sampledCacheManagerDelegate.getMaxBytesLocalOffHeapAsString();
543
325
    }
544
326
 
545
327
    /**
546
328
     * {@inheritDoc}
547
329
     *
548
 
     * @see net.sf.ehcache.management.sampled.SampledCacheManagerMBean#getName()
 
330
     * @see net.sf.ehcache.management.sampled.SampledCacheManager#getName()
549
331
     */
550
332
    public String getName() {
551
 
        return cacheManager.getName();
 
333
        return sampledCacheManagerDelegate.getName();
 
334
    }
 
335
 
 
336
    /**
 
337
     * @see net.sf.ehcache.management.sampled.SampledCacheManager#getClusterUUID()
 
338
     */
 
339
    public String getClusterUUID() {
 
340
        return sampledCacheManagerDelegate.getClusterUUID();
552
341
    }
553
342
 
554
343
    /**
564
353
     * {@inheritDoc}
565
354
     */
566
355
    public void clearStatistics() {
567
 
        for (String cacheName : getCacheNames()) {
568
 
            Cache cache = cacheManager.getCache(cacheName);
569
 
            if (cache != null) {
570
 
                cache.clearStatistics();
571
 
            }
572
 
        }
 
356
        sampledCacheManagerDelegate.clearStatistics();
573
357
        sendNotification(STATISTICS_RESET);
574
358
    }
575
359
 
577
361
     * {@inheritDoc}
578
362
     */
579
363
    public void enableStatistics() {
580
 
        for (String cacheName : getCacheNames()) {
581
 
            Cache cache = cacheManager.getCache(cacheName);
582
 
            if (cache != null) {
583
 
                // enables regular statistics also
584
 
                cache.setSampledStatisticsEnabled(true);
585
 
            }
586
 
        }
 
364
        sampledCacheManagerDelegate.enableStatistics();
587
365
        sendNotification(STATISTICS_ENABLED, Boolean.TRUE);
588
366
    }
589
367
 
591
369
     * {@inheritDoc}
592
370
     */
593
371
    public void disableStatistics() {
594
 
        for (String cacheName : getCacheNames()) {
595
 
            Cache cache = cacheManager.getCache(cacheName);
596
 
            if (cache != null) {
597
 
                // disables regular statistics also
598
 
                cache.setStatisticsEnabled(false);
599
 
            }
600
 
        }
 
372
        sampledCacheManagerDelegate.disableStatistics();
601
373
        sendNotification(STATISTICS_ENABLED, Boolean.FALSE);
602
374
    }
603
375
 
616
388
     * {@inheritDoc}
617
389
     */
618
390
    public boolean isStatisticsEnabled() {
619
 
        for (String cacheName : getCacheNames()) {
620
 
            Cache cache = cacheManager.getCache(cacheName);
621
 
            if (cache != null) {
622
 
                if (!cache.isSampledStatisticsEnabled()) {
623
 
                    return false;
624
 
                }
625
 
            }
626
 
        }
627
 
        return true;
628
 
    }
629
 
 
630
 
    /**
631
 
     * @return is each cache's statistics enabled
632
 
     */
633
 
    private boolean determineStatisticsEnabled() {
634
 
        for (String cacheName : getCacheNames()) {
635
 
            Cache cache = cacheManager.getCache(cacheName);
636
 
            if (cache != null) {
637
 
                if (!cache.isStatisticsEnabled()) {
638
 
                    return false;
639
 
                }
640
 
            }
641
 
        }
642
 
        return true;
 
391
        return sampledCacheManagerDelegate.isStatisticsEnabled();
643
392
    }
644
393
 
645
394
    /**
648
397
     * @return CacheManager configuration as String
649
398
     */
650
399
    public String generateActiveConfigDeclaration() {
651
 
        return this.cacheManager.getActiveConfigurationText();
 
400
        return sampledCacheManagerDelegate.generateActiveConfigDeclaration();
652
401
    }
653
402
 
654
403
    /**
657
406
     * @return Cache configuration as String
658
407
     */
659
408
    public String generateActiveConfigDeclaration(String cacheName) {
660
 
        return this.cacheManager.getActiveConfigurationText(cacheName);
 
409
        return sampledCacheManagerDelegate.generateActiveConfigDeclaration(cacheName);
661
410
    }
662
411
 
663
412
    /**
664
413
     * {@inheritDoc}
665
414
     */
666
415
    public boolean getTransactional() {
667
 
        for (String cacheName : getCacheNames()) {
668
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
669
 
            if (cache != null && cache.getCacheConfiguration().getTransactionalMode().isTransactional()) {
670
 
                return true;
671
 
            }
672
 
        }
673
 
        return false;
 
416
        return sampledCacheManagerDelegate.getTransactional();
674
417
    }
675
418
 
676
419
    /**
677
420
     * {@inheritDoc}
678
421
     */
679
422
    public boolean getSearchable() {
680
 
        for (String cacheName : getCacheNames()) {
681
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
682
 
            if (cache != null && cache.getCacheConfiguration().getSearchable() != null) {
683
 
                return true;
684
 
            }
685
 
        }
686
 
        return false;
 
423
        return sampledCacheManagerDelegate.getSearchable();
687
424
    }
688
425
 
689
426
    /**
690
427
     * {@inheritDoc}
691
428
     */
692
429
    public long getTransactionCommittedCount() {
693
 
        return this.cacheManager.getTransactionController().getTransactionCommittedCount();
 
430
        return sampledCacheManagerDelegate.getTransactionCommittedCount();
694
431
    }
695
432
 
696
433
    /**
697
434
     * {@inheritDoc}
698
435
     */
699
436
    public long getTransactionCommitRate() {
700
 
        long result = 0;
701
 
        for (String cacheName : getCacheNames()) {
702
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
703
 
            if (cache != null) {
704
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
705
 
                result += stats.getCacheXaCommitsMostRecentSample();
706
 
            }
707
 
        }
708
 
        return result;
 
437
        return sampledCacheManagerDelegate.getTransactionCommitRate();
709
438
    }
710
439
 
711
440
    /**
712
441
     * {@inheritDoc}
713
442
     */
714
443
    public long getTransactionRolledBackCount() {
715
 
        return this.cacheManager.getTransactionController().getTransactionRolledBackCount();
 
444
        return sampledCacheManagerDelegate.getTransactionRolledBackCount();
716
445
    }
717
446
 
718
447
    /**
719
448
     * {@inheritDoc}
720
449
     */
721
450
    public long getTransactionRollbackRate() {
722
 
        long result = 0;
723
 
        for (String cacheName : getCacheNames()) {
724
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
725
 
            if (cache != null) {
726
 
                SampledCacheStatistics stats = cache.getSampledCacheStatistics();
727
 
                result += stats.getCacheXaRollbacksMostRecentSample();
728
 
            }
729
 
        }
730
 
        return result;
 
451
        return sampledCacheManagerDelegate.getTransactionRollbackRate();
731
452
    }
732
453
 
733
454
    /**
734
455
     * {@inheritDoc}
735
456
     */
736
457
    public long getTransactionTimedOutCount() {
737
 
        return this.cacheManager.getTransactionController().getTransactionTimedOutCount();
 
458
        return sampledCacheManagerDelegate.getTransactionTimedOutCount();
738
459
    }
739
460
 
740
461
    /**
741
462
     * Returns if each contained cache is enabled.
742
463
     */
743
464
    public boolean isEnabled() throws CacheException {
744
 
        for (String cacheName : getCacheNames()) {
745
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
746
 
            if (cache != null && cache.isDisabled()) {
747
 
                return false;
748
 
            }
749
 
        }
750
 
        return true;
 
465
        return sampledCacheManagerDelegate.isEnabled();
751
466
    }
752
467
 
753
468
    /**
754
469
     * Enables/disables each of the contained caches.
755
470
     */
756
471
    public void setEnabled(boolean enabled) {
757
 
        for (String cacheName : getCacheNames()) {
758
 
            Ehcache cache = cacheManager.getEhcache(cacheName);
759
 
            if (cache != null) {
760
 
                cache.setDisabled(!enabled);
761
 
            }
762
 
        }
763
 
        sendNotification(CACHES_ENABLED, Boolean.valueOf(enabled));
764
 
    }
765
 
 
766
 
    /**
767
 
     * @return is each cache enabled
768
 
     */
769
 
    private boolean determineEnabled() {
770
 
        for (String cacheName : getCacheNames()) {
771
 
            Cache cache = cacheManager.getCache(cacheName);
772
 
            if (cache != null) {
773
 
                if (cache.isDisabled()) {
774
 
                    return false;
775
 
                }
776
 
            }
777
 
        }
778
 
        return true;
779
 
    }
780
 
 
781
 
    /**
782
 
     * getCacheManagerAttributes
783
 
     *
784
 
     * @return map of attribute name -> value
785
 
     */
786
 
    public Map<String, Object> getCacheManagerAttributes() {
 
472
        sampledCacheManagerDelegate.setEnabled(enabled);
 
473
        sendNotification(CACHES_ENABLED, enabled);
 
474
    }
 
475
 
 
476
    /**
 
477
     * @see BaseEmitterBean#getNotificationInfo()
 
478
     */
 
479
    @Override
 
480
    public MBeanNotificationInfo[] getNotificationInfo() {
 
481
        return NOTIFICATION_INFO;
 
482
    }
 
483
 
 
484
    private Map<String, Object> getCacheManagerAttributes() {
787
485
        Map<String, Object> result = new HashMap<String, Object>();
788
486
        result.put("MaxBytesLocalHeapAsString", getMaxBytesLocalHeapAsString());
789
487
        result.put("MaxBytesLocalOffHeapAsString", getMaxBytesLocalOffHeapAsString());
793
491
        result.put("MaxBytesLocalDisk", getMaxBytesLocalDisk());
794
492
        return result;
795
493
    }
796
 
 
797
 
    /**
798
 
     * @see BaseEmitterBean#getNotificationInfo()
799
 
     */
800
 
    @Override
801
 
    public MBeanNotificationInfo[] getNotificationInfo() {
802
 
        return NOTIFICATION_INFO;
803
 
    }
804
494
}