/** * {@inheritDoc} */ public AdvancedCache<CacheKey, Object> getAdvancedCache() { return parentCache.getAdvancedCache(); }
@Override public Cache<?, ?> getCache() { // Retrieve the advanced cache as a way to retrieve // the cache behind the cache adapter. return cache.getAdvancedCache(); }
@Override public AdvancedCache<K, V> getAdvancedCache() { return cache.getAdvancedCache(); }
protected AdvancedCache<?, ?> wrapCache(AdvancedCache<?, ?> cache, boolean isIndexed) { DataConversion valueDataConversion = cache.getAdvancedCache().getValueDataConversion(); if (valueDataConversion.isStorageFormatFilterable()) { cache = cache.withEncoding(IdentityEncoder.class); } return cache; }
private void tryRegisterMigrationManager(AdvancedCache<byte[], byte[]> cache) { ComponentRegistry cr = SecurityActions.getCacheComponentRegistry(cache.getAdvancedCache()); RollingUpgradeManager migrationManager = cr.getComponent(RollingUpgradeManager.class); if (migrationManager != null) migrationManager.addSourceMigrator(new HotRodSourceMigrator(cache)); }
AdvancedCache getCacheInstance(KeyValuePair<String, String> requestTypes, HotRodHeader header, String cacheName, EmbeddedCacheManager cacheManager, Boolean skipCacheCheck, Boolean addToKnownCaches) { AdvancedCache cache = null; String scopedCacheKey = getDecoratedCacheKey(cacheName, requestTypes); if (!skipCacheCheck) cache = knownCaches.get(scopedCacheKey); if (cache == null) { String validCacheName = cacheName.isEmpty() ? configuration.defaultCacheName() : cacheName; cache = SecurityActions.getCache(cacheManager, validCacheName).getAdvancedCache(); Configuration cacheConfiguration = SecurityActions.getCacheConfiguration(cache); // We don't need synchronization as long as we store the cache last knownCacheConfigurations.put(cacheName, cacheConfiguration); knownCacheRegistries.put(cacheName, SecurityActions.getCacheComponentRegistry(cache.getAdvancedCache())); cache = cache.withMediaType(requestTypes.getKey(), requestTypes.getValue()); if (addToKnownCaches) { knownCaches.put(scopedCacheKey, cache); } // make sure we register a Migrator for this cache! tryRegisterMigrationManager(cache); } return cache; }
/** * Get the cache with the given name from the cache manager. Can be used to request additional * caches from the cache manager that are not covered by explicit methods. * * @param name * @return */ public synchronized Cache getCacheByName(String name) { if(!cacheManager.cacheExists(name)) { cacheManager.defineConfiguration(name, new ConfigurationBuilder().read(defaultConfiguration).build()); } return cacheManager.getCache(name).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP); }
@Test public void getDefaultCache() { @SuppressWarnings("unchecked") AdvancedCache<Object, Object> cache = mock(AdvancedCache.class); when(this.manager.getCache("default", true)).thenReturn(cache); when(cache.getAdvancedCache()).thenReturn(cache); Cache<Object, Object> result = this.subject.getCache(); assertNotSame(cache, result); assertEquals(result, cache); assertSame(this.subject, result.getCacheManager()); }
private static Cache mockCache(String nodeName, Configuration configuration, TimeService timeService) { String cacheName = "mock-cache"; AdvancedCache cache = mock(AdvancedCache.class, RETURNS_DEEP_STUBS); GlobalConfiguration gc = new GlobalConfigurationBuilder() .transport().nodeName(nodeName) .build(); Set<String> cachesSet = new HashSet<>(); EmbeddedCacheManager cm = mock(EmbeddedCacheManager.class); when(cm.getCacheManagerConfiguration()).thenReturn(gc); GlobalComponentRegistry gcr = new GlobalComponentRegistry(gc, cm, cachesSet); BasicComponentRegistry gbcr = gcr.getComponent(BasicComponentRegistry.class); gbcr.replaceComponent(TimeService.class.getName(), timeService, true); ComponentRegistry registry = new ComponentRegistry(cacheName, configuration, cache, gcr, configuration.getClass().getClassLoader()); when(cache.getClassLoader()).thenReturn(PersistenceMockUtil.class.getClassLoader()); when(cache.getCacheManager().getCacheManagerConfiguration()) .thenReturn(gc); when(cache.getName()).thenReturn(cacheName); when(cache.getAdvancedCache()).thenReturn(cache); when(cache.getComponentRegistry()).thenReturn(registry); when(cache.getStatus()).thenReturn(ComponentStatus.RUNNING); when(cache.getCacheConfiguration()).thenReturn(configuration); return cache; }
public void testSingleCommitCommand() throws Exception { cache.put("k", "v"); CommitCommandCounterInterceptor counterInterceptor = new CommitCommandCounterInterceptor(); cache.getAdvancedCache().addInterceptor(counterInterceptor, 0); try { tm().begin(); AssertJUnit.assertEquals("Wrong value for key k.", "v", cache.get("k")); tm().commit(); } finally { cache.getAdvancedCache().getAdvancedCache().removeInterceptor(counterInterceptor.getClass()); } AssertJUnit.assertEquals("Wrong number of CommitCommand.", numberCommitCommand(), counterInterceptor.counter.get()); }
.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES) .remove(key); break; case ADD: CacheDecorators.skipCacheStore(cache) .getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES) .put(key, sessionWrapper, task.getLifespanMs(), TimeUnit.MILLISECONDS); break;
@Test public void getCache() { @SuppressWarnings("unchecked") AdvancedCache<Object, Object> defaultCache = mock(AdvancedCache.class); @SuppressWarnings("unchecked") AdvancedCache<Object, Object> otherCache = mock(AdvancedCache.class); when(this.manager.getCache("default", true)).thenReturn(defaultCache); when(this.manager.getCache("other", true)).thenReturn(otherCache); when(defaultCache.getAdvancedCache()).thenReturn(defaultCache); when(otherCache.getAdvancedCache()).thenReturn(otherCache); Cache<Object, Object> result = this.subject.getCache("default"); assertNotSame(defaultCache, result); assertEquals(result, defaultCache); assertSame(this.subject, result.getCacheManager()); result = this.subject.getCache("other"); assertNotSame(otherCache, result); assertEquals(result, otherCache); assertSame(this.subject, result.getCacheManager()); result = this.subject.getCache(CacheContainer.DEFAULT_CACHE_NAME); assertNotSame(defaultCache, result); assertEquals(result, defaultCache); assertSame(this.subject, result.getCacheManager()); result = this.subject.getCache(null); assertNotSame(defaultCache, result); assertEquals(result, defaultCache); assertSame(this.subject, result.getCacheManager()); }
AdvancedCache remotePPCache = remoteCustomerCache.getCacheManager().getCache( remoteCustomerCache.getName() + "-" + InfinispanProperties.DEF_PENDING_PUTS_RESOURCE).getAdvancedCache(); remotePPCache.getAdvancedCache().addInterceptor(hookInterceptor, 0);
distInterceptorBarrier.await(10, TimeUnit.SECONDS); if (cache2.getAdvancedCache().getDistributionManager().getPrimaryLocation(key).equals(address(2))) {
public void testStreamWithMissedKeyInTransaction() throws Exception { AdvancedCache<Object, String> cache = advancedCache(0, CACHE_NAME); TransactionManager tm = tm(cache); tm.begin(); try { Object localMissingKey = new MagicKey("key1", cache); Object remoteMissingKey = new MagicKey("key2", cache(1, CACHE_NAME)); assertFalse(cache.containsKey(localMissingKey)); assertFalse(cache.containsKey(remoteMissingKey)); Iterator<CacheEntry<Object, String>> iterator = cache.getAdvancedCache().cacheEntrySet().stream().iterator(); Map<Object, String> results = mapFromIterator(iterator); assertEquals(Collections.emptyMap(), results); // size() also uses streams internally assertEquals(0, cache.size()); } finally { tm.rollback(); } } }
protected void doTestIgnoreReturnValueAndRead(boolean executeOnPrimaryOwner) throws Exception { final Object key = new MagicKey("ignore-previous-value", cache(0)); final AdvancedCache<Object, Object> c = executeOnPrimaryOwner ? advancedCache(0) : advancedCache(1); final TransactionManager tm = executeOnPrimaryOwner ? tm(0) : tm(1); for (Cache cache : caches()) { assertNull("wrong initial value for " + address(cache) + ".", cache.get(key)); } c.put("k", "init"); tm.begin(); c.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put("k", "v1"); assertEquals("v1", c.put("k", "v2")); Transaction tx = tm.suspend(); assertEquals("init", c.put("k", "other")); tm.resume(tx); tm.commit(); }
Object createStatsResponse() { Stats stats = cache.getAdvancedCache().getStats(); StringBuilder sb = new StringBuilder(); return new ByteBuf[]{
assertFalse(cache0.getAdvancedCache().getLockManager().isLocked(key)); assertFalse(cache1.getAdvancedCache().getLockManager().isLocked(key)); assertFalse(cache2.getAdvancedCache().getLockManager().isLocked(key));
expiredCache = expiredCache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_OWNERSHIP_CHECK); otherCache = otherCache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_OWNERSHIP_CHECK);
log.tracef("Adding additional value on nonOwner value inserted: %s = %s", mk, value); primaryOwnerCache.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore( new BlockingInterceptor<>(cyclicBarrier, getVisitableCommand(op), true, false), StateTransferInterceptor.class);