private void resetCache(final Cache<Object, Object> cache) { if (cache.getCacheConfiguration().invocationBatching().enabled()) { cache.endBatch(false); } TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); try { if (tm.getTransaction() != null) { tm.rollback(); } } catch (Exception e) { } }
private void resetCache(final Cache<Object, Object> cache) { Configuration configuration = SecurityActions.getCacheConfiguration(cache.getAdvancedCache()); if (configuration.invocationBatching().enabled()) { SecurityActions.endBatch(cache.getAdvancedCache()); } TransactionManager tm = cache.getAdvancedCache().getTransactionManager(); try { if (tm != null && tm.getTransaction() != null) { tm.rollback(); } } catch (Exception e) { // Ignore the exception } }
/** * Creates a TreeCache instance by taking in a {@link org.infinispan.Cache} as a parameter * * @param cache * @return instance of a {@link TreeCache} * @throws NullPointerException if the cache parameter is null * @throws CacheConfigurationException if the invocation batching configuration is not enabled. */ public <K, V> TreeCache<K, V> createTreeCache(Cache<K, V> cache) { // Validation to make sure that the cache is not null. if (cache == null) { throw new NullPointerException("The cache parameter passed in is null"); } // If invocationBatching is not enabled, throw a new configuration exception. if (!cache.getCacheConfiguration().invocationBatching().enabled()) { throw new CacheConfigurationException("invocationBatching is not enabled for cache '" + cache.getName() + "'. Make sure this is enabled by" + " calling configurationBuilder.invocationBatching().enable()"); } return new TreeCacheImpl<K, V>(cache); } }
cacheConfigurationDependencies.getTemplateConfigurationInjector()); if (config.invocationBatching().enabled()) { cacheConfigurationDependencies.getTransactionManagerInjector().inject(BatchModeTransactionManager.getInstance()); } else if (config.transaction().transactionMode() == org.infinispan.transaction.TransactionMode.TRANSACTIONAL) {
public void testDefineConfigurationTwice() { EmbeddedCacheManager cm = createCacheManager(false); try { Configuration override = new ConfigurationBuilder().invocationBatching().enable().build(); assertTrue(override.invocationBatching().enabled()); assertTrue(cm.defineConfiguration("test1", override).invocationBatching().enabled()); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.read(override); Configuration config = cb.build(); assertTrue(config.invocationBatching().enabled()); assertTrue(cm.defineConfiguration("test2", config).invocationBatching().enabled()); } finally { cm.stop(); } }
public void testBatchingIsEnabled() throws Exception { EmbeddedCacheManager cm = TestCacheManagerFactory.fromXml("configs/batching.xml"); try { Cache c = cm.getCache("default"); assertTrue(c.getCacheConfiguration().invocationBatching().enabled()); assertTrue(c.getCacheConfiguration().transaction().transactionMode().isTransactional()); c = cm.getCache(); assertTrue(c.getCacheConfiguration().invocationBatching().enabled()); Cache c2 = cm.getCache("tml"); assertTrue(c2.getCacheConfiguration().transaction().transactionMode().isTransactional()); } finally { cm.stop(); } }
public void testBatchingAndTransactionalCache() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.invocationBatching().enable(); final Configuration c = cb.build(); assert c.invocationBatching().enabled(); assert c.transaction().transactionMode().isTransactional(); withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager()) { @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(); } }); } }
@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(); } });
@Override public <T extends OutgoingDistributableSessionData> org.jboss.as.clustering.web.DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager) throws ClusteringNotSupportedException { @SuppressWarnings("unchecked") Registry<String, Void> jvmRouteRegistry = this.registry.getValue(); @SuppressWarnings("unchecked") AdvancedCache<String, Map<Object, Object>> cache = this.cache.getValue().getAdvancedCache(); if (!cache.getCacheConfiguration().invocationBatching().enabled()) { ServiceName cacheServiceName = this.getCacheServiceName(manager.getReplicationConfig()); throw new ClusteringNotSupportedException(MESSAGES.failedToConfigureWebApp(cacheServiceName.getParent().getSimpleName(), cacheServiceName.getSimpleName())); } BatchingManager batchingManager = new TransactionBatchingManager(cache.getTransactionManager()); SessionAttributeStorage<T> storage = this.storageFactory.createStorage(manager.getReplicationConfig().getReplicationGranularity(), this.marshallerFactory.createMarshaller(manager)); return new DistributedCacheManager<T>(manager, new AtomicMapCache<String, Object, Object>(cache), jvmRouteRegistry, this.lockManager.getOptionalValue(), storage, batchingManager, this.invoker, this.affinityFactory.getValue()); }
assertFalse(c.invocationBatching().enabled()); assertTrue(c.jmxStatistics().enabled()); assertEquals(CacheMode.LOCAL, c.clustering().cacheMode()); assertTrue(c.invocationBatching().enabled()); assertTrue(c.jmxStatistics().enabled()); assertEquals(30500, c.locking().lockAcquisitionTimeout()); assertTrue(c.invocationBatching().enabled()); assertTrue(c.jmxStatistics().enabled()); assertEquals(31000, c.locking().lockAcquisitionTimeout()); assertFalse(c.invocationBatching().enabled()); assertEquals(1200000, c.clustering().l1().lifespan()); assertEquals(4, c.clustering().hash().numOwners()); assertEquals(CacheMode.REPL_SYNC, c.clustering().cacheMode()); assertTrue(c.invocationBatching().enabled()); assertEquals(CacheMode.REPL_SYNC, c.clustering().cacheMode()); assertTrue(c.invocationBatching().enabled()); assertEquals(CacheMode.REPL_SYNC, c.clustering().cacheMode()); assertTrue(c.invocationBatching().enabled());