Java Code Examples for org.infinispan.configuration.cache.ConfigurationBuilder#build()
The following examples show how to use
org.infinispan.configuration.cache.ConfigurationBuilder#build() .
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: InfinispanReplicated.java From infinispan-simple-tutorials with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Setup up a clustered cache manager GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); // Initialize the cache manager DefaultCacheManager cacheManager = new DefaultCacheManager(global.build()); // Create a replicated synchronous configuration ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(CacheMode.REPL_SYNC); Configuration cacheConfig = builder.build(); // Create a cache Cache<String, String> cache = cacheManager.administration() .withFlags(CacheContainerAdmin.AdminFlag.VOLATILE) .getOrCreateCache("cache", cacheConfig); // Store the current node address in some random keys for(int i=0; i < 10; i++) { cache.put(UUID.randomUUID().toString(), cacheManager.getNodeAddress()); } // Display the current cache contents for the whole cluster cache.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue())); // Display the current cache contents for this node cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP) .entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue())); // Stop the cache manager and release all resources cacheManager.stop(); }
Example 2
Source File: ClusterManager.java From glowroot with Apache License 2.0 | 6 votes |
private static Configuration createCacheConfiguration(int size) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); // "max idle" is to keep memory down for deployments with few agents // "size" is to keep memory bounded for deployments with lots of agents configurationBuilder.clustering() .cacheMode(CacheMode.INVALIDATION_ASYNC) .expiration() .maxIdle(30, MINUTES) .memory() .size(size) .evictionType(EvictionType.COUNT) .evictionStrategy(EvictionStrategy.REMOVE) .jmxStatistics() .enable(); return configurationBuilder.build(); }
Example 3
Source File: DefaultInfinispanConnectionProviderFactory.java From keycloak with Apache License 2.0 | 6 votes |
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 4
Source File: ConcurrencyLockingTest.java From keycloak with Apache License 2.0 | 6 votes |
protected DefaultCacheManager getVersionedCacheManager() { GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); boolean allowDuplicateJMXDomains = true; gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains); final DefaultCacheManager cacheManager = new DefaultCacheManager(gcb.build()); ConfigurationBuilder invalidationConfigBuilder = new ConfigurationBuilder(); Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build(); cacheManager.defineConfiguration(InfinispanConnectionProvider.REALM_CACHE_NAME, invalidationCacheConfiguration); ConfigurationBuilder counterConfigBuilder = new ConfigurationBuilder(); counterConfigBuilder.invocationBatching().enable(); counterConfigBuilder.transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup()); counterConfigBuilder.transaction().lockingMode(LockingMode.PESSIMISTIC); Configuration counterCacheConfiguration = counterConfigBuilder.build(); cacheManager.defineConfiguration("COUNTER_CACHE", counterCacheConfiguration); return cacheManager; }
Example 5
Source File: L1SerializationIssueTest.java From keycloak with Apache License 2.0 | 6 votes |
private EmbeddedCacheManager createManager() { System.setProperty("java.net.preferIPv4Stack", "true"); System.setProperty("jgroups.tcp.port", "53715"); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); gcb = gcb.clusteredDefault(); gcb.transport().clusterName("test-clustering"); gcb.globalJmxStatistics().allowDuplicateDomains(true); EmbeddedCacheManager cacheManager = new DefaultCacheManager(gcb.build()); ConfigurationBuilder distConfigBuilder = new ConfigurationBuilder(); ClusteringConfigurationBuilder clusterConfBuilder = distConfigBuilder.clustering(); clusterConfBuilder.cacheMode(CacheMode.DIST_SYNC); clusterConfBuilder.hash().numOwners(NUM_OWNERS); clusterConfBuilder.l1().enabled(L1_ENABLED) .lifespan(L1_LIFESPAN_MS) .cleanupTaskFrequency(L1_CLEANER_MS); Configuration distCacheConfiguration = distConfigBuilder.build(); cacheManager.defineConfiguration(CACHE_NAME, distCacheConfiguration); return cacheManager; }
Example 6
Source File: InfinispanKeyStorageProviderTest.java From keycloak with Apache License 2.0 | 6 votes |
protected Cache<String, PublicKeysEntry> getKeysCache() { GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); gcb.globalJmxStatistics().allowDuplicateDomains(true).enabled(true); final DefaultCacheManager cacheManager = new DefaultCacheManager(gcb.build()); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.memory() .evictionStrategy(EvictionStrategy.REMOVE) .evictionType(EvictionType.COUNT) .size(InfinispanConnectionProvider.KEYS_CACHE_DEFAULT_MAX); cb.jmxStatistics().enabled(true); Configuration cfg = cb.build(); cacheManager.defineConfiguration(InfinispanConnectionProvider.KEYS_CACHE_NAME, cfg); return cacheManager.getCache(InfinispanConnectionProvider.KEYS_CACHE_NAME); }
Example 7
Source File: DataGridManager.java From hacep with Apache License 2.0 | 5 votes |
public void startCacheInfo(String nodeName) { if (startedCacheInfo.compareAndSet(false, true)) { GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder().clusteredDefault() .transport().addProperty("configurationFile", System.getProperty("jgroups.configuration.info", "jgroups-tcp-info.xml")) .clusterName("HACEPINFO").nodeName(nodeName+"INFO") .globalJmxStatistics().allowDuplicateDomains(true).enable() .serialization() .build(); ConfigurationBuilder commonConfigurationBuilder = new ConfigurationBuilder(); commonConfigurationBuilder.clustering().cacheMode(CacheMode.REPL_SYNC); Configuration commonConfiguration = commonConfigurationBuilder.build(); this.managerCacheInfo = new DefaultCacheManager(globalConfiguration, commonConfiguration, false); ConfigurationBuilder replicatedInfos = new ConfigurationBuilder(); replicatedInfos.clustering().cacheMode(CacheMode.REPL_SYNC); if (persistence()) { replicatedInfos .persistence() .passivation(false) .addSingleFileStore() .shared(false) .preload(true) .fetchPersistentState(true) .purgeOnStartup(false) .location(location()) .async().threadPoolSize(threadPoolSize()).enabled(false) .singleton().enabled(false); } this.managerCacheInfo.defineConfiguration(REPLICATED_CACHE_NAME, replicatedInfos.build()); this.managerCacheInfo.start(); } }
Example 8
Source File: InfinispanTx.java From infinispan-simple-tutorials with Apache License 2.0 | 5 votes |
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 9
Source File: DefaultInfinispanConnectionProviderFactory.java From keycloak with Apache License 2.0 | 5 votes |
protected Configuration getKeysCacheConfig() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.memory() .evictionStrategy(EvictionStrategy.REMOVE) .evictionType(EvictionType.COUNT) .size(InfinispanConnectionProvider.KEYS_CACHE_DEFAULT_MAX); cb.expiration().maxIdle(InfinispanConnectionProvider.KEYS_CACHE_MAX_IDLE_SECONDS, TimeUnit.SECONDS); return cb.build(); }
Example 10
Source File: ClusteredCacheBehaviorTest.java From keycloak with Apache License 2.0 | 5 votes |
public EmbeddedCacheManager createManager() { System.setProperty("java.net.preferIPv4Stack", "true"); System.setProperty("jgroups.tcp.port", "53715"); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); boolean clustered = true; boolean async = false; boolean allowDuplicateJMXDomains = true; if (clustered) { gcb = gcb.clusteredDefault(); gcb.transport().clusterName("test-clustering"); } gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains); EmbeddedCacheManager cacheManager = new DefaultCacheManager(gcb.build()); ConfigurationBuilder invalidationConfigBuilder = new ConfigurationBuilder(); 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 11
Source File: OutdatedTopologyExceptionReproducerTest.java From keycloak with Apache License 2.0 | 5 votes |
private EmbeddedCacheManager createManager() { System.setProperty("java.net.preferIPv4Stack", "true"); System.setProperty("jgroups.tcp.port", "53715"); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); boolean clustered = true; boolean async = false; boolean allowDuplicateJMXDomains = true; if (clustered) { gcb = gcb.clusteredDefault(); gcb.transport().clusterName("test-clustering"); } gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains); EmbeddedCacheManager cacheManager = new DefaultCacheManager(gcb.build()); ConfigurationBuilder invalidationConfigBuilder = new ConfigurationBuilder(); if (clustered) { invalidationConfigBuilder.clustering().cacheMode(async ? CacheMode.INVALIDATION_ASYNC : CacheMode.INVALIDATION_SYNC); } // Uncomment this to have test fixed!!! // invalidationConfigBuilder.customInterceptors() // .addInterceptor() // .before(NonTransactionalLockingInterceptor.class) // .interceptorClass(StateTransferInterceptor.class); Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build(); cacheManager.defineConfiguration(InfinispanConnectionProvider.REALM_CACHE_NAME, invalidationCacheConfiguration); return cacheManager; }
Example 12
Source File: ConcurrencyVersioningTest.java From keycloak with Apache License 2.0 | 5 votes |
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 13
Source File: DistributedCacheConcurrentWritesTest.java From keycloak with Apache License 2.0 | 5 votes |
public static EmbeddedCacheManager createManager(String nodeName) { System.setProperty("java.net.preferIPv4Stack", "true"); System.setProperty("jgroups.tcp.port", "53715"); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); boolean clustered = true; boolean async = false; boolean allowDuplicateJMXDomains = true; if (clustered) { gcb = gcb.clusteredDefault(); gcb.transport().clusterName("test-clustering"); gcb.transport().nodeName(nodeName); } gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains); EmbeddedCacheManager cacheManager = new DefaultCacheManager(gcb.build()); ConfigurationBuilder distConfigBuilder = new ConfigurationBuilder(); if (clustered) { distConfigBuilder.clustering().cacheMode(async ? CacheMode.DIST_ASYNC : CacheMode.DIST_SYNC); distConfigBuilder.clustering().hash().numOwners(1); // Disable L1 cache distConfigBuilder.clustering().hash().l1().enabled(false); } Configuration distConfig = distConfigBuilder.build(); cacheManager.defineConfiguration(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME, distConfig); return cacheManager; }
Example 14
Source File: DataGridManager.java From hacep with Apache License 2.0 | 4 votes |
public void start(HAKieSessionBuilder builder, String nodeName) { if (started.compareAndSet(false, true)) { GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder().clusteredDefault() .transport().addProperty("configurationFile", System.getProperty("jgroups.configuration", "jgroups-tcp.xml")) .clusterName("HACEP").nodeName(nodeName) .globalJmxStatistics().allowDuplicateDomains(true).enable() .serialization() .addAdvancedExternalizer(new HAKieSession.HASessionExternalizer(builder)) .addAdvancedExternalizer(new HAKieSerializedSession.HASerializedSessionExternalizer(builder)) .addAdvancedExternalizer(new HAKieSessionDeltaEmpty.HASessionDeltaEmptyExternalizer(builder)) .addAdvancedExternalizer(new HAKieSessionDeltaFact.HASessionDeltaFactExternalizer(builder)) .build(); ConfigurationBuilder commonConfigurationBuilder = new ConfigurationBuilder(); CacheMode cacheMode = getCacheMode(); if (cacheMode.isDistributed()) { commonConfigurationBuilder .clustering().cacheMode(cacheMode) .hash().numOwners(getNumOwners()) .groups().enabled(); } else { commonConfigurationBuilder.clustering().cacheMode(cacheMode); } Configuration commonConfiguration = commonConfigurationBuilder.build(); this.manager = new DefaultCacheManager(globalConfiguration, commonConfiguration, false); ConfigurationBuilder factCacheConfigurationBuilder = new ConfigurationBuilder().read(commonConfiguration); factCacheConfigurationBuilder .expiration() .maxIdle(factsExpiration(), TimeUnit.MILLISECONDS); ConfigurationBuilder sessionCacheConfigurationBuilder = new ConfigurationBuilder().read(commonConfiguration); if (persistence()) { sessionCacheConfigurationBuilder .persistence() .passivation(isPassivated()) .addSingleFileStore() .shared(shared()) .preload(preload()) .fetchPersistentState(fetchPersistentState()) .purgeOnStartup(purgeOnStartup()) .location(location()) .async().threadPoolSize(threadPoolSize()).enabled(false) .singleton().enabled(false) .eviction() .strategy(EvictionStrategy.LRU).type(EvictionType.COUNT).size(evictionSize()); } this.manager.defineConfiguration(FACT_CACHE_NAME, factCacheConfigurationBuilder.build()); this.manager.defineConfiguration(SESSION_CACHE_NAME, sessionCacheConfigurationBuilder.build()); this.manager.start(); } }
Example 15
Source File: DistributedCacheWriteSkewTest.java From keycloak with Apache License 2.0 | 4 votes |
public static EmbeddedCacheManager createManager(String nodeName) { System.setProperty("java.net.preferIPv4Stack", "true"); System.setProperty("jgroups.tcp.port", "53715"); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); boolean clustered = true; boolean async = false; boolean allowDuplicateJMXDomains = true; if (clustered) { gcb = gcb.clusteredDefault(); gcb.transport().clusterName("test-clustering"); gcb.transport().nodeName(nodeName); } gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains); EmbeddedCacheManager cacheManager = new DefaultCacheManager(gcb.build()); ConfigurationBuilder distConfigBuilder = new ConfigurationBuilder(); if (clustered) { distConfigBuilder.clustering().cacheMode(async ? CacheMode.DIST_ASYNC : CacheMode.DIST_SYNC); distConfigBuilder.clustering().hash().numOwners(1); // Disable L1 cache distConfigBuilder.clustering().hash().l1().enabled(false); //distConfigBuilder.storeAsBinary().enable().storeKeysAsBinary(false).storeValuesAsBinary(true); distConfigBuilder.versioning().enabled(true); distConfigBuilder.versioning().scheme(VersioningScheme.SIMPLE); distConfigBuilder.locking().writeSkewCheck(true); distConfigBuilder.locking().isolationLevel(IsolationLevel.REPEATABLE_READ); distConfigBuilder.locking().concurrencyLevel(32); distConfigBuilder.locking().lockAcquisitionTimeout(1000, TimeUnit.SECONDS); distConfigBuilder.versioning().enabled(true); distConfigBuilder.versioning().scheme(VersioningScheme.SIMPLE); // distConfigBuilder.invocationBatching().enable(); //distConfigBuilder.transaction().transactionMode(TransactionMode.TRANSACTIONAL); distConfigBuilder.transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup()); distConfigBuilder.transaction().lockingMode(LockingMode.OPTIMISTIC); } Configuration distConfig = distConfigBuilder.build(); cacheManager.defineConfiguration(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME, distConfig); return cacheManager; }