org.infinispan.transaction.TransactionMode Java Examples

The following examples show how to use org.infinispan.transaction.TransactionMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultInfinispanConnectionProviderFactory.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private Configuration getRevisionCacheConfig(long maxEntries) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.invocationBatching().enable().transaction().transactionMode(TransactionMode.TRANSACTIONAL);

    // Use Embedded manager even in managed ( wildfly/eap ) environment. We don't want infinispan to participate in global transaction
    cb.transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup());

    cb.transaction().lockingMode(LockingMode.PESSIMISTIC);

    cb.memory()
            .evictionStrategy(EvictionStrategy.REMOVE)
            .evictionType(EvictionType.COUNT)
            .size(maxEntries);

    return cb.build();
}
 
Example #2
Source File: DeviceManagementCacheProvider.java    From enmasse with Apache License 2.0 5 votes vote down vote up
public org.infinispan.configuration.cache.Configuration buildDeviceManagementConfiguration() {
    return new org.infinispan.configuration.cache.ConfigurationBuilder()

            .indexing()
            .index(Index.PRIMARY_OWNER)
            .addProperty("default.indexmanager", "org.infinispan.query.indexmanager.InfinispanIndexManager")
            .addProperty("default.worker.execution", "async")
            .addProperty("default.index_flush_interval", "500")
            .addIndexedEntity(DeviceInformation.class)
            .addIndexedEntity(DeviceCredential.class)

            // .persistence()
            // .addSingleFileStore()
            // .fetchPersistentState(true)

            .clustering()
            .cacheMode(CacheMode.DIST_SYNC)
            .hash()
            .numOwners(1)

            .invocationBatching()
            .enable()

            .transaction()
            .autoCommit(true)
            .transactionMode(TransactionMode.TRANSACTIONAL)
            .useSynchronization(true)
            .recovery().disable()

            .locking()
            .isolationLevel(IsolationLevel.READ_COMMITTED)

            .build();
}
 
Example #3
Source File: InfinispanTx.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   // Construct a local cache manager
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   // Create a transaction cache config
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL);
   Configuration cacheConfig = builder.build();
   // Create a cache with the config
   Cache<String, String> cache = cacheManager.administration()
           .withFlags(CacheContainerAdmin.AdminFlag.VOLATILE)
           .getOrCreateCache("cache", cacheConfig);
   // Obtain the transaction manager
   TransactionManager transactionManager = cache.getAdvancedCache().getTransactionManager();
   // Perform some operations within a transaction and commit it
   transactionManager.begin();
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   transactionManager.commit();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Perform some operations within a transaction and roll it back
   transactionManager.begin();
   cache.put("key1", "value3");
   cache.put("key2", "value4");
   transactionManager.rollback();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
Example #4
Source File: ConcurrencyVersioningTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected DefaultCacheManager getVersionedCacheManager() {
    GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder();


    boolean clustered = false;
    boolean async = false;
    boolean allowDuplicateJMXDomains = true;

    if (clustered) {
        gcb.transport().defaultTransport();
    }
    gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains);

    final DefaultCacheManager cacheManager = new DefaultCacheManager(gcb.build());
    ConfigurationBuilder invalidationConfigBuilder = new ConfigurationBuilder();
    invalidationConfigBuilder
            //.invocationBatching().enable()
            .transaction().transactionMode(TransactionMode.TRANSACTIONAL)
            .transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup())
            .locking().isolationLevel(IsolationLevel.REPEATABLE_READ).writeSkewCheck(true).versioning().enable().scheme(VersioningScheme.SIMPLE);


    //invalidationConfigBuilder.locking().isolationLevel(IsolationLevel.REPEATABLE_READ).writeSkewCheck(true).versioning().enable().scheme(VersioningScheme.SIMPLE);

    if (clustered) {
        invalidationConfigBuilder.clustering().cacheMode(async ? CacheMode.INVALIDATION_ASYNC : CacheMode.INVALIDATION_SYNC);
    }
    Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build();
    cacheManager.defineConfiguration(InfinispanConnectionProvider.REALM_CACHE_NAME, invalidationCacheConfiguration);
    return cacheManager;
}
 
Example #5
Source File: CacheConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
private Configuration transactionalConfiguration() {
    return new ConfigurationBuilder().transaction().transactionMode(TransactionMode.TRANSACTIONAL).lockingMode(LockingMode.PESSIMISTIC).build();
}