@Override public PersistenceConfiguration get() { PersistenceConfiguration persistence = super.get(); StoreConfiguration store = persistence.stores().get(0); try { @SuppressWarnings("unchecked") Class<StoreConfigurationBuilder<?, ?>> storeClass = (Class<StoreConfigurationBuilder<?, ?>>) this.module.get().getClassLoader().loadClass(this.className).asSubclass(StoreConfigurationBuilder.class); return new ConfigurationBuilder().persistence().passivation(persistence.passivation()).addStore(storeClass) .async().read(store.async()) .fetchPersistentState(store.fetchPersistentState()) .preload(store.preload()) .purgeOnStartup(store.purgeOnStartup()) .shared(store.shared()) .withProperties(store.properties()) .persistence().create(); } catch (ClassNotFoundException | ClassCastException e) { throw InfinispanLogger.ROOT_LOGGER.invalidCacheStore(e, this.className); } }
public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
private static <T> T getStoreConfiguration(Configuration c, Class<T> configurationClass) { for (StoreConfiguration pc: c.persistence().stores()) { if (configurationClass.isInstance(pc)) { return (T) pc; } } throw new NoSuchElementException("There is no store of type " + configurationClass); }
@Override public void accept(ConfigurationBuilder builder) { super.accept(builder); builder.clustering().cacheMode(CacheMode.LOCAL); // Auto-enable simple cache optimization if cache is non-transactional and non-persistent builder.simpleCache((this.memory().storageType() == StorageType.OBJECT) && !this.transaction().transactionMode().isTransactional() && !this.persistence().usingStores()); } }
private static void validateMetadataCache(Cache<?, ?> cache, String indexName) { Configuration configuration = cache.getCacheConfiguration(); if (configuration.memory().isEvictionEnabled()) { throw log.evictionNotAllowedInMetadataCache(indexName, cache.getName()); } if (configuration.persistence().usingStores() && !configuration.persistence().preload()) { throw log.preloadNeededIfPersistenceIsEnabledForMetadataCache(indexName, cache.getName()); } }
assertTrue(c.persistence().preload()); assertTrue(!c.persistence().passivation()); assertEquals(1, c.persistence().stores().size()); SingleFileStoreConfiguration loaderCfg = (SingleFileStoreConfiguration) c.persistence().stores().get(0); assertEquals(1, c.persistence().stores().size()); ClusterLoaderConfiguration clusterLoaderCfg = (ClusterLoaderConfiguration) c.persistence().stores().get(0); assertEquals(15000, clusterLoaderCfg.remoteCallTimeout()); loaderCfg = (SingleFileStoreConfiguration) c.persistence().stores().get(0); assertEquals("/tmp/Another-FileCacheStore-Location", loaderCfg.location());
@Override public void check(ConfigurationBuilderHolder holder) { Configuration local = getConfiguration(holder, "local"); PersistenceConfiguration persistenceConfiguration = local.persistence(); assertEquals(5, persistenceConfiguration.connectionAttempts()); assertEquals(100, persistenceConfiguration.connectionInterval()); assertEquals(2000, persistenceConfiguration.availabilityInterval()); assertFalse(persistenceConfiguration.stores().isEmpty()); AsyncStoreConfiguration asyncConfig = persistenceConfiguration.stores().iterator().next().async(); assertTrue(asyncConfig.failSilently()); } },
protected void doPreloadingTest(Configuration preloadingCfg, String cacheName) throws Exception { assertTrue("Preload not enabled for preload test", preloadingCfg.persistence().preload()); cm.defineConfiguration(cacheName, preloadingCfg); Cache<String, String> preloadingCache = getCache(cm, cacheName); AdvancedCacheLoader preloadingCacheLoader = (AdvancedCacheLoader) TestingUtil.getCacheLoader(preloadingCache); assert preloadingCache.getCacheConfiguration().persistence().preload(); assert preloadingCache.getCacheConfiguration().persistence().preload(); c = preloadingCache.getAdvancedCache().getDataContainer(); assertEquals(4, c.size());
compareAttributeSets(name, configurationBefore.indexing().attributes(), configurationAfter.indexing().attributes()); compareAttributeSets(name, configurationBefore.locking().attributes(), configurationAfter.locking().attributes()); compareAttributeSets(name, configurationBefore.persistence().attributes(), configurationAfter.persistence().attributes()); compareStores(name, configurationBefore.persistence().stores(), configurationAfter.persistence().stores()); compareAttributeSets(name, configurationBefore.security().authorization().attributes(), configurationAfter.security().authorization().attributes()); compareAttributeSets(name, configurationBefore.transaction().attributes(), configurationAfter.transaction().attributes(), "transaction-manager-lookup");
ExceptionTrackerInterceptor interceptor = getInterceptor(cache); assertTrue("Preload should be enabled.", cache.getCacheConfiguration().persistence().preload()); assertTrue("Async Store should be enabled.", cache.getCacheConfiguration().persistence().usingAsyncStore()); assertTrue("Preload should be enabled after restart.", cache.getCacheConfiguration().persistence().preload()); assertTrue("Async Store should be enabled after restart.", cache.getCacheConfiguration().persistence().usingAsyncStore());
private StoreConfiguration buildCacheManagerWithCacheStore(final String config) throws IOException { InputStream is = new ByteArrayInputStream(config.getBytes()); cacheManager = TestCacheManagerFactory.fromStream(is); assert cacheManager.getDefaultCacheConfiguration().persistence().stores().size() == 1; return cacheManager.getDefaultCacheConfiguration().persistence().stores().get(0); } }
@Start protected void start() { Set<Class<?>> indexedEntities = cacheConfiguration.indexing().indexedEntities(); this.indexedEntities = indexedEntities.isEmpty() ? null : indexedEntities.toArray(new Class<?>[indexedEntities.size()]); queryKnownClasses = indexedEntities.isEmpty() ? new QueryKnownClasses(cache.getName(), cache.getCacheManager(), internalCacheRegistry) : new QueryKnownClasses(cache.getName(), indexedEntities); searchFactoryHandler = new SearchFactoryHandler(searchFactory, queryKnownClasses, new TransactionHelper(cache.getTransactionManager())); if (this.indexedEntities == null) { queryKnownClasses.start(searchFactoryHandler); Set<Class<?>> classes = queryKnownClasses.keys(); Class<?>[] classesArray = classes.toArray(new Class<?>[classes.size()]); //Important to enable them all in a single call, much more efficient: searchFactoryHandler.enableClasses(classesArray); } isPersistenceEnabled = cacheConfiguration.persistence().usingStores(); stopping.set(false); }
private static void validateMetadataCache(Cache<?, ?> cache, String indexName) { Configuration configuration = cache.getCacheConfiguration(); if (configuration.memory().isEvictionEnabled()) { throw log.evictionNotAllowedInMetadataCache(indexName, cache.getName()); } if (configuration.persistence().usingStores() && !configuration.persistence().preload()) { throw log.preloadNeededIfPersistenceIsEnabledForMetadataCache(indexName, cache.getName()); } }
public void testPreloadAndExpiry() { assert cache.getCacheConfiguration().persistence().preload(); cache.put("k1", "v"); cache.put("k2", "v", 111111, TimeUnit.MILLISECONDS); cache.put("k3", "v", -1, TimeUnit.MILLISECONDS, 222222, TimeUnit.MILLISECONDS); cache.put("k4", "v", 333333, TimeUnit.MILLISECONDS, 444444, TimeUnit.MILLISECONDS); assertCacheEntry(cache, "k1", "v", -1, -1); assertCacheEntry(cache, "k2", "v", 111111, -1); assertCacheEntry(cache, "k3", "v", -1, 222222); assertCacheEntry(cache, "k4", "v", 333333, 444444); cache.stop(); cache.start(); cl = getAdvancedLoadWriteStore(); assertCacheEntry(cache, "k1", "v", -1, -1); assertCacheEntry(cache, "k2", "v", 111111, -1); assertCacheEntry(cache, "k3", "v", -1, 222222); assertCacheEntry(cache, "k4", "v", 333333, 444444); }
public void testLoaders() { List<StoreConfiguration> stores = cacheManager.getCache("customLoaderCache").getCacheConfiguration().persistence().stores(); assertEquals(stores.size(), 1); StoreConfiguration storeConfiguration = stores.get(0); assertTrue(storeConfiguration instanceof ClusterLoaderConfiguration); ClusterLoaderConfiguration csc = (ClusterLoaderConfiguration) storeConfiguration; assertEquals(csc.remoteCallTimeout(), 1222); } }
if (cache.getCacheConfiguration().persistence().usingStores()) { final boolean passivationOn = cache.getCacheConfiguration().persistence().passivation();
@Override public PersistenceConfiguration get() { PersistenceConfiguration persistence = super.get(); StoreConfiguration store = persistence.stores().get(0); try { @SuppressWarnings("unchecked") Class<StoreConfigurationBuilder<?, ?>> storeClass = (Class<StoreConfigurationBuilder<?, ?>>) this.module.get().getClassLoader().loadClass(this.className).asSubclass(StoreConfigurationBuilder.class); return new ConfigurationBuilder().persistence().passivation(persistence.passivation()).addStore(storeClass) .async().read(store.async()) .fetchPersistentState(store.fetchPersistentState()) .preload(store.preload()) .purgeOnStartup(store.purgeOnStartup()) .shared(store.shared()) .withProperties(store.properties()) .persistence().create(); } catch (ClassNotFoundException | ClassCastException e) { throw InfinispanLogger.ROOT_LOGGER.invalidCacheStore(e, this.className); } }
public static <K, V> CacheLoader<K, V> getCacheLoader(Cache<K, V> cache) { if (cache.getCacheConfiguration().persistence().usingStores()) { return TestingUtil.getFirstLoader(cache); } else { return null; } }
private static void validateMetadataCache(Cache<?, ?> cache, String indexName) { Configuration configuration = cache.getCacheConfiguration(); if (configuration.eviction().strategy().isEnabled()) { throw log.evictionNotAllowedInMetadataCache(indexName, cache.getName()); } if (configuration.persistence().usingStores() && !configuration.persistence().preload()) { throw log.preloadNeededIfPersistenceIsEnabledForMetadataCache(indexName, cache.getName()); } }
protected void doPreloadingTestWithEviction(Configuration preloadingCfg, String cacheName) throws Exception { assertTrue("Preload not enabled for preload with eviction test", preloadingCfg.persistence().preload()); assertTrue("Eviction not enabled for preload with eviction test", preloadingCfg.memory().isEvictionEnabled()); preloadingCache.getCacheConfiguration().persistence().preload()); assertNotInCacheAndStore(preloadingCache, preloadingCacheLoader, "k1", "k2", "k3", "k4"); preloadingCache.getCacheConfiguration().persistence().preload());