regionAttrsFactory.setCacheListener(new ConfigurationChangeListener(this, cache)); regionAttrsFactory.setDiskStoreName(CLUSTER_CONFIG_DISK_STORE_NAME); regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
public static void main1(String[] args) throws Exception { DistributedSystem system = DistributedSystem.connect(new java.util.Properties()); Cache cache = CacheFactory.create(system); AttributesFactory factory = new AttributesFactory(); factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK)); factory.setCacheListener(new CacheListenerAdapter() { @Override public void afterUpdate(EntryEvent event) { System.out.println("UPDATE: " + event.getKey() + " -> (" + event.getOldValue() + " -> " + event.getNewValue() + ")"); } }); LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create()); DiskRegion dr = region.getDiskRegion(); DiskRegionStats diskStats = dr.getStats(); EvictionCounters lruStats = getLRUStats(region); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Hit enter to perform action"); for (int i = 0; true; i++) { br.readLine(); // Thread.sleep(500); Object key = new Integer(i); Object value = new byte[200000]; region.put(key, value); System.out.println(key + " -> " + value + " evictions = " + lruStats.getEvictions() + ", writes = " + diskStats.getWrites()); } }
public void afterDestroy2(EntryEvent e) {} }; factory.setCacheListener(list); RegionAttributes attrs = factory.create();
public void afterInvalidate2(EntryEvent e) {} }; factory.setCacheListener(list); RegionAttributes attrs = factory.create();
fac.setCacheListener(list);
assertEquals(Arrays.asList(new CacheListener[0]), Arrays.asList(ra.getCacheListeners())); factory.setCacheListener(cl1); ra = factory.create(); assertEquals(cl1, ra.getCacheListener()); assertEquals(Arrays.asList(new CacheListener[] {cl1}), Arrays.asList(ra.getCacheListeners())); factory.setCacheListener(cl2); ra = factory.create(); assertEquals(cl2, ra.getCacheListener()); assertEquals(Arrays.asList(new CacheListener[] {cl2}), Arrays.asList(ra.getCacheListeners())); factory.setCacheListener(null); ra = factory.create(); assertEquals(null, ra.getCacheListener()); assertEquals(Arrays.asList(new CacheListener[0]), Arrays.asList(ra.getCacheListeners())); factory.setCacheListener(cl1); factory.initCacheListeners(new CacheListener[] {cl1, cl2}); ra = factory.create();
factory.setStatisticsEnabled(true); RegionAttributes subRegAttrs = factory.create(); factory.setCacheListener(list); RegionAttributes attrs = factory.create();