Search in sources :

Example 1 with MultiLevelCache

use of com.alicp.jetcache.MultiLevelCache in project jetcache by alibaba.

the class DefaultCacheMonitorTest method testWithManager.

@Test
public void testWithManager() throws Exception {
    Cache c1 = createCache();
    DefaultCacheMonitor m1 = new DefaultCacheMonitor("cache1");
    Cache c2 = createCache();
    DefaultCacheMonitor m2 = new DefaultCacheMonitor("cache2");
    c1.config().getMonitors().add(m1);
    c2.config().getMonitors().add(m2);
    DefaultMetricsManager manager = new DefaultMetricsManager(10, TimeUnit.SECONDS, true);
    manager.start();
    manager.add(m1, m2);
    basetest(c1, m1);
    basetest(c2, m2);
    Cache mc = new MultiLevelCache(c1, c2);
    DefaultCacheMonitor mcm = new DefaultCacheMonitor("multiCache");
    mc.config().getMonitors().add(mcm);
    manager.add(mcm);
    basetest(mc, mcm);
    manager.cmd.run();
    manager.stop();
// Thread.sleep(10000);
}
Also used : MultiLevelCache(com.alicp.jetcache.MultiLevelCache) Cache(com.alicp.jetcache.Cache) MultiLevelCache(com.alicp.jetcache.MultiLevelCache) Test(org.junit.Test)

Example 2 with MultiLevelCache

use of com.alicp.jetcache.MultiLevelCache in project jetcache by alibaba.

the class DefaultCacheMonitorManager method addMetricsMonitor.

protected void addMetricsMonitor(String area, String cacheName, Cache cache) {
    if (defaultMetricsManager != null) {
        cache = CacheUtil.getAbstractCache(cache);
        if (cache instanceof MultiLevelCache) {
            MultiLevelCache mc = (MultiLevelCache) cache;
            if (mc.caches().length == 2) {
                Cache local = mc.caches()[0];
                Cache remote = mc.caches()[1];
                DefaultCacheMonitor localMonitor = new DefaultCacheMonitor(cacheName + "_local");
                local.config().getMonitors().add(localMonitor);
                DefaultCacheMonitor remoteMonitor = new DefaultCacheMonitor(cacheName + "_remote");
                remote.config().getMonitors().add(remoteMonitor);
                defaultMetricsManager.add(localMonitor, remoteMonitor);
            }
        }
        DefaultCacheMonitor monitor = new DefaultCacheMonitor(cacheName);
        cache.config().getMonitors().add(monitor);
        defaultMetricsManager.add(monitor);
    }
}
Also used : MultiLevelCache(com.alicp.jetcache.MultiLevelCache) Cache(com.alicp.jetcache.Cache) MultiLevelCache(com.alicp.jetcache.MultiLevelCache)

Aggregations

Cache (com.alicp.jetcache.Cache)2 MultiLevelCache (com.alicp.jetcache.MultiLevelCache)2 Test (org.junit.Test)1