@Override public int size() { return cache.size(); }
@Override public int size() { return cache.size(); }
@Override public int size() { return cache.size(); }
@Override public void run() { while (!Thread.interrupted()) { System.out.println("Cache: " + alias + " size:" + icache.size()); if (!sleepMillis(2000)) { return; } } } });
void assertSize() { int size = cache.size(); if (size > max) { max = size; } if (size > estimatedMaxSize) { fail(name + ": cache " + cache.getName() + " toleranceFactor=" + toleranceFactor + " configuredMaxSize=" + configuredMaxSize + " estimatedMaxSize=" + estimatedMaxSize + " size=" + cache.size() ); } } }
@Override public void run() throws Exception { int cacheSize = cache.size(); logger.info(name + " ICache size: " + cacheSize); assertEquals(name + " ICache should be empty, but TTL events are not processed", 0, cacheSize); } });
/** * List the distributed objects in the grid. */ @SuppressWarnings("resource") @CliCommand(value = "list", help = "List distributed objects") public void list() { log.info("-----------------------"); Collection<DistributedObject> distributedObjects = this.hazelcastInstance.getDistributedObjects(); for (DistributedObject distributedObject : distributedObjects) { log.info("Distributed Object => name '{}'", distributedObject.getName()); if (distributedObject instanceof ICache) { ICache<?, ?> iCache = (ICache<?, ?>) distributedObject; log.info(" -> ICACHE => size {}", iCache.size()); } } if (distributedObjects.size() > 0) { log.info("-----------------------"); } log.info("[{} distributed object{}]", distributedObjects.size(), (distributedObjects.size() == 1 ? "" : "s") ); log.info("-----------------------"); } }
System.out.println("cache size: " + cache.size());
@Verify public void globalVerify() { Counter totalCounter = new Counter(); for (Counter counter : results) { totalCounter.add(counter); } logger.info(name + " " + totalCounter + " from " + results.size() + " worker Threads"); for (int i = 0; i < keyCount; i++) { assertFalse(name + " ICache should not contain key " + i, cache.containsKey(i)); } assertFalse(name + " ICache iterator should not have elements", cache.iterator().hasNext()); assertEquals(name + " ICache size should be 0", 0, cache.size()); } }
@Verify public void globalVerify() { IList<Integer> results = targetInstance.getList(name + "max"); int observedMaxSize = 0; for (int m : results) { if (observedMaxSize < m) { observedMaxSize = m; } } logger.info(name + ": cache " + cache.getName() + " toleranceFactor=" + toleranceFactor + " configuredMaxSize=" + configuredMaxSize + " estimatedMaxSize=" + estimatedMaxSize + " observedMaxSize=" + observedMaxSize + " size=" + cache.size() ); IList<Counter> counters = targetInstance.getList(name + "counter"); Counter total = new Counter(); for (Counter c : counters) { total.add(c); } logger.info(name + ": " + total); logger.info(name + ": putAllMap size=" + putAllMap.size()); }
public static void main(String[] args) { // Run as a Hazelcast Client System.setProperty("hazelcast.jcache.provider.type", "client"); // Create the JCache CacheManager CacheManager manager = Caching.getCachingProvider().getCacheManager(); MutableConfiguration<String, String> configuration = new MutableConfiguration<String, String>(); // Expire entries after 1 minute configuration.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); // Get a Cache called "myCache" and configure with 1 minute expiry Cache<String, String> myCache = manager.createCache("myCache", configuration); // Put and Get a value from "myCache" myCache.put("key", "value"); String value = myCache.get("key"); System.out.println(value); //ICache is a Hazelcast interface that extends JCache, provides more functionality ICache<String, String> icache = myCache.unwrap(ICache.class); //Async Get and Put using ICache interface icache.getAsync("key"); icache.putAsync("key", "value"); //ICache allows custom expiry per cache entry final ExpiryPolicy customExpiryPolicy = AccessedExpiryPolicy.factoryOf(Duration.TEN_MINUTES).create(); icache.put("key", "newValue", customExpiryPolicy); //Size of the Cache should reflect the ICache and JCache operations icache.size(); //Shutdown this Hazelcast Client manager.getCachingProvider().close(); } }
public static void main(String[] args) { // Run as a Hazelcast Member System.setProperty("hazelcast.jcache.provider.type", "server"); // Create the JCache CacheManager CacheManager manager = Caching.getCachingProvider().getCacheManager(); MutableConfiguration<String, String> configuration = new MutableConfiguration<String, String>(); // Expire entries after 1 minute configuration.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); // Get a Cache called "myCache" and configure with 1 minute expiry Cache<String, String> myCache = manager.createCache("myCache", configuration); // Put and Get a value from "myCache" myCache.put("key", "value"); String value = myCache.get("key"); System.out.println(value); //ICache is a Hazelcast interface that extends JCache, provides more functionality ICache<String, String> icache = myCache.unwrap(ICache.class); //Async Get and Put using ICache interface icache.getAsync("key"); icache.putAsync("key", "value"); //ICache allows custom expiry per cache entry final ExpiryPolicy customExpiryPolicy = AccessedExpiryPolicy.factoryOf(Duration.TEN_MINUTES).create(); icache.put("key", "newValue", customExpiryPolicy); //Size of the Cache should reflect the ICache and JCache operations icache.size(); //Shutdown the underlying Hazelcast Cluster Member manager.getCachingProvider().close(); } }