@Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) throws CacheEntryListenerException { for (CacheEntryEvent<? extends Integer, ? extends Integer> e : evts) { cntr.incrementAndGet(); ClusterNode node = ((Ignite)e.getSource().unwrap(Ignite.class)).cluster().localNode(); Set<Integer> set = maps.get(node); if (set == null) { set = new ConcurrentSkipListSet<>(); Set<Integer> oldVal = maps.putIfAbsent(node, set); set = oldVal != null ? oldVal : set; } if (!set.add(e.getValue())) doubleNtfFail.set(false); } } };
@Test public void testCacheUnwrap() { MutableConfiguration<String, String> configuration = new MutableConfiguration<>(); configuration.setTypes(String.class, String.class); Cache<String, String> cache = cacheManager.createCache("cache", configuration); assertThat(cache.unwrap(org.ehcache.Cache.class), is(instanceOf(org.ehcache.Cache.class))); assertThat(cache.unwrap(cache.getClass()), is(instanceOf(Eh107Cache.class))); cacheManager.close(); }
@Override public <T> T unwrap(Class<T> clazz) { return cache.unwrap(clazz); }
@SuppressWarnings("unchecked") public static <K, V> ICache<K, V> getCache(HazelcastCacheManager cacheManager, String cacheName) { return cacheManager.getCache(cacheName).unwrap(ICache.class); }
private void run() { ICache<Object, Object> cache = cacheManager.getCache(NAMESPACE).unwrap(ICache.class); for (int i = 0; i < threadCount; i++) { executorService.execute(new CacheTestRunnable(allStats[i], cache)); } }
static ICache createCache(String cacheName) { Cache<Object, Object> cache = cacheManager.createCache(cacheName, createCacheConfig(cacheName)); return cache.unwrap(ICache.class); }
ICache<Object, Object> cache = cacheManager.getCache("cache").unwrap(ICache.class); CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);
@Override public void createSchema() { if (manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass) == null) { cacheEntryList.clear(); cache = manager.createCache(persistentClass.getSimpleName(), cacheConfig).unwrap(ICache.class); } cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>( JCacheCacheFactoryBuilder .factoryOfEntryListener(new JCacheCacheEntryListener<K, T>(cacheEntryList)), null, true, true)); persistentDataStore.createSchema(); LOG.info("Created schema on persistent store and initialized cache for persistent bean {}." , super.getPersistentClass().getSimpleName()); }
@SuppressWarnings("unchecked") @Override public <K, V> Cache<K, V> getCache(String _cacheName) { checkClosed(); checkNonNullCacheName(_cacheName); synchronized (getLockObject()) { Cache<K, V> c = name2adapter.get(_cacheName); if (c != null && manager.getCache(_cacheName) == c.unwrap(org.cache2k.Cache.class) && !c.isClosed()) { return c; } if (configuredCacheNames.contains(_cacheName)) { return createCache(_cacheName, new MutableConfiguration<K, V>()); } } return null; }
/** * Will fail unless CacheImpl specified in pom.xml */ @Test public void testCacheUnwrap() { final Class<?> unwrapClass = getUnwrapClass(Cache.class); final Object unwrappedCache = cache.unwrap(unwrapClass); assertTrue(unwrapClass.isAssignableFrom(unwrappedCache.getClass())); }
@Override public void createSchema() throws GoraException { try { if (manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass) == null) { cacheEntryList.clear(); cache = manager.createCache(persistentClass.getSimpleName(), cacheConfig).unwrap(ICache.class); } cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>( JCacheCacheFactoryBuilder .factoryOfEntryListener(new JCacheCacheEntryListener<K, T>(cacheEntryList)), null, true, true)); persistentDataStore.createSchema(); LOG.info("Created schema on persistent store and initialized cache for persistent bean {}." , super.getPersistentClass().getSimpleName()); } catch (GoraException e) { throw e; } catch (Exception e) { throw new GoraException(e); } }
ICache<Object, Object> cache = cacheManager.getCache("cache").unwrap(ICache.class); CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class); Iterable<CacheEntryListenerConfiguration> cacheEntryListenerConfigurations
ICache<Object, Object> cache = cacheManager.getCache("cache").unwrap(ICache.class); CacheConfig cacheConfig = cache.getConfiguration(CacheConfig.class);
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String _cacheName, C cfg) throws IllegalArgumentException { checkClosed(); checkNonNullCacheName(_cacheName); synchronized (getLockObject()) { Cache _jsr107cache = name2adapter.get(_cacheName); if (_jsr107cache != null && !_jsr107cache.isClosed()) { throw new CacheException("cache already existing with name: " + _cacheName); } org.cache2k.Cache _existingCache = manager.getCache(_cacheName); if (_existingCache != null && !_existingCache.isClosed()) { throw new CacheException("A cache2k instance is already existing with name: " + _cacheName); } JCacheBuilder<K,V> _builder = new JCacheBuilder<K, V>(_cacheName, this); _builder.setConfiguration(cfg); Cache<K,V> _cache = _builder.build(); org.cache2k.Cache _cache2k = _cache.unwrap(org.cache2k.Cache.class); Map<org.cache2k.Cache, Cache> _cloneC2k2jCache = new WeakHashMap<org.cache2k.Cache, Cache>(c2k2jCache); _cloneC2k2jCache.put(_cache2k, _cache); c2k2jCache = _cloneC2k2jCache; name2adapter.put(_cache.getName(), _cache); if (_builder.isStatisticsEnabled()) { enableStatistics(_cacheName, true); } if (_builder.isManagementEnabled()) { enableManagement(_cacheName, true); } return _cache; } }
@Override public void call() { cm.defineConfiguration("UnwrapCache", new ConfigurationBuilder().build()); CacheManager jCacheManager = new JCacheManager(URI.create("UnwrapCacheManager"), cm, null); Cache<Object, Object> jcache = jCacheManager.getCache("UnwrapCache"); assertTrue(jCacheManager.unwrap(JCacheManager.class) != null); assertTrue(jcache.unwrap(JCache.class) != null); assertTrue(jCacheManager.unwrap(EmbeddedCacheManager.class) != null); assertTrue(jcache.unwrap(org.infinispan.Cache.class) != null); } });
public void testJCacheManagerWithWildcardCacheConfigurations() throws Exception { URI uri = JCacheConfigurationTest.class.getClassLoader().getResource("infinispan_uri.xml").toURI(); withCachingProvider(provider -> { JCacheManager jCacheManager = new JCacheManager( uri, provider.getClass().getClassLoader(), provider, null); Cache<Object, Object> wildcache1 = jCacheManager.createCache("wildcache1", new MutableConfiguration<>()); org.infinispan.Cache unwrap = wildcache1.unwrap(org.infinispan.Cache.class); Configuration configuration = unwrap.getCacheConfiguration(); assertEquals(10500, configuration.expiration().wakeUpInterval()); assertEquals(11, configuration.expiration().lifespan()); assertEquals(11, configuration.expiration().maxIdle()); }); }
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(); } }
DataContainer<Integer, String> dc = cache.unwrap(AdvancedCache.class).getDataContainer();