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()); }
Address localAddress = this.group.getAddress(this.group.getLocalMember()); try (Batch batch = this.batcher.createBatch()) { this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS, Flag.IGNORE_RETURN_VALUES).compute(service, this.properties.isTransactional() ? new CopyOnWriteSetRemoveFunction<>(localAddress) : new ConcurrentSetRemoveFunction<>(localAddress)); } finally { Map.Entry<Listener, ExecutorService> oldEntry = this.listeners.remove(service); WildFlySecurityManager.doUnchecked(action); try { executor.awaitTermination(this.cache.getCacheConfiguration().transaction().cacheStopTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt();
@Override public void accept(ConfigurationBuilder builder) { TransactionConfiguration tx = this.transaction.get(); builder.memory().read(this.memory.get()); builder.expiration().read(this.expiration.get()); builder.locking().read(this.locking.get()); builder.persistence().read(this.persistence.get()); builder.transaction().read(tx); builder.jmxStatistics().enabled(this.statisticsEnabled).available(this.statisticsEnabled); try { // Configure invocation batching based on transaction configuration builder.invocationBatching().enable(tx.transactionMode().isTransactional() && (tx.transactionManagerLookup().getTransactionManager() != ContextTransactionManager.getInstance())); } catch (Exception e) { throw new CacheException(e); } }
@Test public final void testAddConfigurations() throws Exception { final InfinispanEmbeddedCacheManagerFactoryBean objectUnderTest = new InfinispanEmbeddedCacheManagerFactoryBean(); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); // Now prepare a cache configuration. ConfigurationBuilder builder = new ConfigurationBuilder(); builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); // Now add them to the object that we are testing. objectUnderTest.addCustomGlobalConfiguration(gcb); objectUnderTest.addCustomCacheConfiguration(builder); objectUnderTest.afterPropertiesSet(); // Get the cache manager and make assertions. final EmbeddedCacheManager infinispanEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals(infinispanEmbeddedCacheManager.getCacheManagerConfiguration().globalJmxStatistics() .allowDuplicateDomains(), gcb.build().globalJmxStatistics().allowDuplicateDomains()); assertEquals(infinispanEmbeddedCacheManager.getDefaultCacheConfiguration().transaction() .transactionMode().isTransactional(), builder.build().transaction().transactionMode().isTransactional()); } }
public void testTransactionModeOverride() { ConfigurationBuilder c = new ConfigurationBuilder(); c.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL); assertEquals(TransactionMode.TRANSACTIONAL, cacheManager.getCache().getCacheConfiguration().transaction().transactionMode()); cacheManager.defineConfiguration("nonTx", c.build()); assertEquals(TransactionMode.NON_TRANSACTIONAL, cacheManager.getCache("nonTx").getCacheConfiguration().transaction().transactionMode()); }
@Override public void call() { ConfigurationBuilder customConfiguration = TestCacheManagerFactory.getDefaultCacheConfiguration(true); customConfiguration.transaction().transactionManagerLookup(new TxManagerLookupA()); Configuration definedConfiguration = cm.defineConfiguration("aCache", customConfiguration.build()); // verify the setting was not lost: assertTrue(definedConfiguration.transaction().transactionManagerLookup() instanceof TxManagerLookupA); // verify it's actually being used: TransactionManager activeTransactionManager = cm.getCache("aCache").getAdvancedCache().getTransactionManager(); assertNotNull(activeTransactionManager); assertTrue(activeTransactionManager instanceof TmA); } });
/** * Inject our TransactionManager lookup delegate for transactional caches ONLY! * <p> * injecting one in a non-transactional cache will have side-effects on other configuration settings. * * @return an updated version of the configuration */ private static Configuration injectTransactionManager(TransactionManagerLookupDelegator transactionManagerLookupDelegator, Configuration configuration) { if ( configuration.transaction().transactionMode() == TransactionMode.TRANSACTIONAL ) { ConfigurationBuilder builder = new ConfigurationBuilder().read( configuration ); builder.transaction() .transactionManagerLookup( transactionManagerLookupDelegator ); return builder.build(); } return configuration; }
public void testDefaults() { Configuration c = new ConfigurationBuilder().build(); assert !c.transaction().transactionMode().isTransactional(); c = TestCacheManagerFactory.getDefaultCacheConfiguration(false).build(); assert !c.transaction().transactionMode().isTransactional(); c = TestCacheManagerFactory.getDefaultCacheConfiguration(true).build(); assert c.transaction().transactionMode().isTransactional(); c = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false).build(); assert !c.transaction().transactionMode().isTransactional(); c = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true).build(); assert c.transaction().transactionMode().isTransactional(); }
if (cacheManager == null) { EmbeddedCacheManager cacheManager = new DefaultCacheManager(configStream, false); GlobalConfiguration globalConfigFromXml = cacheManager.getCacheManagerConfiguration(); Configuration configFromXml = cacheManager.getDefaultCacheConfiguration(); ConfigurationBuilder configBuilder = new ConfigurationBuilder().read(configFromXml); TransactionManagerLookup tmLookup = configFromXml.transaction().transactionManagerLookup(); if (tmLookup == null) { tmLookup = getTransactionManagerLookup(); configBuilder.transaction().transactionManagerLookup(tmLookup); cacheLifespanOfLeafNodes = configFromXml.expiration().lifespan(); configBuilder.expiration().lifespan(-1); log.debug("Expiration of structure cache entries is disabled. Leaf nodes will use expiration "
assertEquals(TransactionMode.TRANSACTIONAL, c.transaction().transactionMode()); // Full XA assertFalse(c.transaction().useSynchronization()); // Full XA assertTrue(c.transaction().recovery().enabled()); // Full XA assertEquals(LockingMode.OPTIMISTIC, c.transaction().lockingMode()); assertTrue(c.transaction().transactionManagerLookup() instanceof JBossStandaloneJTAManagerLookup); assertEquals(60000, c.transaction().cacheStopTimeout()); assertEquals(TransactionMode.TRANSACTIONAL, c.transaction().transactionMode()); // Non XA assertTrue(c.transaction().useSynchronization()); // Non XA assertFalse(c.transaction().recovery().enabled()); // Non XA assertEquals(LockingMode.OPTIMISTIC, c.transaction().lockingMode()); assertEquals(60500, c.transaction().cacheStopTimeout()); assertEquals(TransactionMode.TRANSACTIONAL, c.transaction().transactionMode()); // Batching, non XA assertTrue(c.transaction().useSynchronization()); // Batching, non XA assertFalse(c.transaction().recovery().enabled()); // Batching, non XA assertEquals(LockingMode.PESSIMISTIC, c.transaction().lockingMode()); assertEquals(61000, c.transaction().cacheStopTimeout()); assertEquals(TransactionMode.TRANSACTIONAL, c.transaction().transactionMode()); // Full XA assertFalse(c.transaction().useSynchronization()); // Full XA assertTrue(c.transaction().recovery().enabled()); // Full XA assertEquals(LockingMode.OPTIMISTIC, c.transaction().lockingMode()); assertEquals(61500, c.transaction().cacheStopTimeout()); assertEquals(TransactionMode.TRANSACTIONAL, c.transaction().transactionMode()); // Non XA assertTrue(c.transaction().useSynchronization()); // Non XA assertFalse(c.transaction().recovery().enabled()); // Non XA
@Override public void call() { cm.defineConfiguration("transactional", c.build()); Cache<?, ?> cache = cm.getCache("transactional"); assert cache.getCacheConfiguration().transaction().transactionMode().isTransactional(); } });
protected void runTest(int index) { assert cache(0).getCacheConfiguration().transaction().transactionMode().isTransactional(); List<Long> internalIds = getInternalIds(recoveryOps(index).showInDoubtTransactions()); assertEquals(internalIds.size(), 1); assertEquals(cache(0).get(key), null); assertEquals(cache(1).get(key), null); log.trace("About to force commit!"); isSuccess(recoveryOps(index).forceCommit(internalIds.get(0))); assertEquals(cache(0).get(key), "newValue"); assertEquals(cache(1).get(key), "newValue"); assertCleanup(0); assertCleanup(1); } }
Address localAddress = this.group.getAddress(this.group.getLocalMember()); try (Batch batch = this.batcher.createBatch()) { Set<Address> addresses = this.cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK).get(service); if ((addresses != null) && addresses.remove(localAddress)) { Cache<T, Set<Address>> cache = this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES); if (addresses.isEmpty()) { cache.remove(service); } else { cache.replace(service, addresses); WildFlySecurityManager.doUnchecked(action); try { executor.awaitTermination(this.cache.getCacheConfiguration().transaction().cacheStopTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt();
assertTrue(externalizers.get(3456) instanceof AdvancedExternalizerTest.IdViaBothObj.Externalizer); Configuration defaultCfg = holder.getDefaultConfigurationBuilder().build(); Configuration c = holder.getNamedConfigurationBuilders().get("transactional").build(); assertTrue(!c.clustering().cacheMode().isClustered()); assertTrue(c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup); if (!deprecated) { assertReaperAndTimeoutInfo(defaultCfg); c = holder.getNamedConfigurationBuilders().get("transactional2").build(); assertTrue(c.transaction().transactionManagerLookup() instanceof TestLookup); assertEquals(10000, c.transaction().cacheStopTimeout()); assertEquals(LockingMode.PESSIMISTIC, c.transaction().lockingMode()); assertTrue(!c.transaction().autoCommit()); c = holder.getNamedConfigurationBuilders().get("transactional3").build(); assertEquals(TransactionProtocol.TOTAL_ORDER, c.transaction().transactionProtocol()); c = holder.getNamedConfigurationBuilders().get("syncInval").build(); c = holder.getNamedConfigurationBuilders().get("txSyncRepl").build(); assertTrue(c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup); assertEquals(CacheMode.REPL_SYNC, c.clustering().cacheMode()); assertTrue(!c.clustering().stateTransfer().fetchInMemoryState());
public void testTransactionalityInduced() { ConfigurationBuilder cb = new ConfigurationBuilder(); Configuration c = cb.build(); assert !c.transaction().transactionMode().isTransactional(); c = cb.transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup()).build(); assert c.transaction().transactionMode().isTransactional(); cb = new ConfigurationBuilder(); cb.invocationBatching().enable(); assert cb.build().transaction().transactionMode().isTransactional(); }
private void createQueryInterceptorIfNeeded(BasicComponentRegistry cr, Configuration cfg, AdvancedCache<?, ?> cache, SearchIntegrator searchIntegrator, KeyTransformationHandler keyTransformationHandler) { log.registeringQueryInterceptor(cache.getName()); ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg); builder.customInterceptors().addInterceptor() .interceptor(queryInterceptor).after(lastLoadingInterceptor.getClass()); if (cfg.transaction().transactionMode().isTransactional()) { TxQueryInterceptor txQueryInterceptor = new TxQueryInterceptor(txOldValues, queryInterceptor); ic.addInterceptorBefore(txQueryInterceptor, wrappingInterceptor.getClass()); cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors());
public TombstoneAccessDelegate(InfinispanDataRegion region) { this.region = region; this.cache = region.getCache(); FunctionalMapImpl<Object, Object> fmap = FunctionalMapImpl.create(cache).withParams(Param.PersistenceMode.SKIP_LOAD); writeMap = ReadWriteMapImpl.create(fmap); // Note that correct behaviour of local and async writes depends on LockingInterceptor (see there for details) asyncWriteMap = ReadWriteMapImpl.create(fmap).withParams(Param.ReplicationMode.ASYNC); putFromLoadMap = ReadWriteMapImpl.create(fmap).withParams(Param.LockingMode.TRY_LOCK, Param.ReplicationMode.ASYNC); Configuration configuration = this.cache.getCacheConfiguration(); if (configuration.clustering().cacheMode().isInvalidation()) { throw new IllegalArgumentException("For tombstone-based caching, invalidation cache is not allowed."); } if (configuration.transaction().transactionMode().isTransactional()) { throw new IllegalArgumentException("Currently transactional caches are not supported."); } requiresTransaction = configuration.transaction().transactionMode().isTransactional() && !configuration.transaction().autoCommit(); }
private void createQueryInterceptorIfNeeded(ComponentRegistry cr, Configuration cfg, SearchIntegrator searchFactory) { QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class); if (queryInterceptor == null) { queryInterceptor = buildQueryInterceptor(cfg, searchFactory, cr.getComponent(Cache.class)); // Interceptor registration not needed, core configuration handling // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in the component registry! AsyncInterceptorChain ic = cr.getComponent(AsyncInterceptorChain.class); ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg); InterceptorConfigurationBuilder interceptorBuilder = builder.customInterceptors().addInterceptor(); interceptorBuilder.interceptor(queryInterceptor); boolean txVersioned = Configurations.isTxVersioned(cfg); boolean isTotalOrder = cfg.transaction().transactionProtocol().isTotalOrder(); Class<? extends DDAsyncInterceptor> wrappingInterceptor = EntryWrappingInterceptor.class; if (txVersioned) { wrappingInterceptor = isTotalOrder ? TotalOrderVersionedEntryWrappingInterceptor.class : VersionedEntryWrappingInterceptor.class; } if (ic != null) ic.addInterceptorAfter(queryInterceptor, wrappingInterceptor); interceptorBuilder.after(wrappingInterceptor); if (ic != null) { cr.registerComponent(queryInterceptor, QueryInterceptor.class); cr.registerComponent(queryInterceptor, queryInterceptor.getClass().getName(), true); } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); } }
@Override public void call() { assert !cm.getCache().getCacheConfiguration().transaction().transactionMode().isTransactional(); cm.defineConfiguration("a", c); final Cache<Object, Object> a = cm.getCache("a"); assert a.getCacheConfiguration().invocationBatching().enabled(); assert a.getCacheConfiguration().transaction().transactionMode().isTransactional(); } });
@Test public void testDistSyncAutoCommit() { Configuration configuration = new ConfigurationBuilder() .clustering().cacheMode(CacheMode.DIST_SYNC) .transaction().autoCommit(true) .build(); Assert.assertTrue(configuration.transaction().autoCommit()); Assert.assertEquals(configuration.clustering().cacheMode(), CacheMode.DIST_SYNC); }