org.infinispan.configuration.global.GlobalConfigurationBuilder Java Examples
The following examples show how to use
org.infinispan.configuration.global.GlobalConfigurationBuilder.
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: InfinispanConfiguration.java From apicurio-registry with Apache License 2.0 | 6 votes |
@ApplicationScoped @Produces public EmbeddedCacheManager cacheManager( @RegistryProperties("registry.infinispan.transport") Properties properties ) { GlobalConfigurationBuilder gConf = GlobalConfigurationBuilder.defaultClusteredBuilder(); gConf.serialization() .marshaller(new JavaSerializationMarshaller()) .whiteList() .addRegexps( "io.apicurio.registry.storage.", TupleId.class.getName(), MapValue.class.getName() ); TransportConfigurationBuilder tConf = gConf.transport(); tConf.clusterName(clusterName); if (properties.size() > 0) { tConf.withProperties(properties); } return new DefaultCacheManager(gConf.build(), true); }
Example #2
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 #3
Source File: TestCacheManagerFactory.java From keycloak with Apache License 2.0 | 6 votes |
<T extends StoreConfigurationBuilder<?, T> & RemoteStoreConfigurationChildBuilder<T>> EmbeddedCacheManager createManager(int threadId, String cacheName, Class<T> builderClass) { System.setProperty("java.net.preferIPv4Stack", "true"); System.setProperty("jgroups.tcp.port", "53715"); GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder(); boolean clustered = false; 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()); Configuration invalidationCacheConfiguration = getCacheBackedByRemoteStore(threadId, cacheName, builderClass); cacheManager.defineConfiguration(cacheName, invalidationCacheConfiguration); cacheManager.defineConfiguration("local", new ConfigurationBuilder().build()); return cacheManager; }
Example #4
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 #5
Source File: InfinispanServerExtension.java From infinispan-spring-boot with Apache License 2.0 | 6 votes |
public void start() { if (hotRodServer == null) { TestResourceTracker.setThreadTestName("InfinispanServer"); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); EmbeddedCacheManager ecm = TestCacheManagerFactory.createCacheManager( new GlobalConfigurationBuilder().nonClusteredDefault().defaultCacheName("default"), configurationBuilder); for (String cacheName : initialCaches) { ecm.createCache(cacheName, new ConfigurationBuilder().build()); } HotRodServerConfigurationBuilder serverBuilder = new HotRodServerConfigurationBuilder(); serverBuilder.adminOperationsHandler(new EmbeddedServerAdminOperationHandler()); hotRodServer = HotRodTestingUtil.startHotRodServer(ecm, host, port, serverBuilder); } }
Example #6
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 #7
Source File: InfinispanDistributed.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 cache configuration ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(CacheMode.DIST_SYNC); // Obtain a cache Cache<String, String> cache = cacheManager.administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE) .getOrCreateCache("cache", builder.build()); // 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 #8
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 #9
Source File: InfinispanServerTestResource.java From quarkus with Apache License 2.0 | 5 votes |
@Override public Map<String, String> start() { TestResourceTracker.setThreadTestName("InfinispanServer"); EmbeddedCacheManager ecm = TestCacheManagerFactory.createCacheManager( new GlobalConfigurationBuilder().nonClusteredDefault().defaultCacheName("default"), new ConfigurationBuilder()); ecm.defineConfiguration("magazine", new ConfigurationBuilder().build()); // Client connects to a non default port hotRodServer = HotRodTestingUtil.startHotRodServer(ecm, 11232); return Collections.emptyMap(); }
Example #10
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 #11
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 #12
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 #13
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 #14
Source File: ClusterManager.java From glowroot with Apache License 2.0 | 5 votes |
private ClusterManagerImpl(File confDir, String jgroupsConfigurationFile, Map<String, String> jgroupsProperties) { GlobalConfiguration configuration = new GlobalConfigurationBuilder() .transport() .defaultTransport() .addProperty("configurationFile", getConfigurationFilePropertyValue(confDir, jgroupsConfigurationFile)) .globalJmxStatistics() .enable() .build(); cacheManager = doWithSystemProperties(jgroupsProperties, () -> new DefaultCacheManager(configuration)); executor = MoreExecutors2.newCachedThreadPool("Cluster-Manager-Worker"); }
Example #15
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 #16
Source File: AbstractClusterTest.java From hacep with Apache License 2.0 | 5 votes |
private DefaultCacheManager clusteredCacheManager(CacheMode mode, int owners, RulesManager rulesManager, String nodeName, String globalStateLocation) { ExecutorService executorService = Executors.newFixedThreadPool(4); HAKieSessionBuilder sessionBuilder = new HAKieSessionBuilder(rulesManager, executorService); TransportConfigurationBuilder tcb = new GlobalConfigurationBuilder().clusteredDefault() .transport().addProperty("configurationFile", System.getProperty("jgroups.configuration", "jgroups-test-tcp.xml")) .clusterName("HACEP"); if(nodeName != null){ tcb.nodeName(nodeName); } GlobalJmxStatisticsConfigurationBuilder gjscb = tcb.globalJmxStatistics().allowDuplicateDomains(true).enable(); GlobalStateConfigurationBuilder gscb; if(globalStateLocation!=null){ gscb = gjscb.globalState().enable().persistentLocation(globalStateLocation); } else { gscb = gjscb.globalState().disable(); } GlobalConfiguration glob = gscb.serialization() .addAdvancedExternalizer(new HAKieSession.HASessionExternalizer(sessionBuilder)) .addAdvancedExternalizer(new HAKieSerializedSession.HASerializedSessionExternalizer(sessionBuilder)) .addAdvancedExternalizer(new HAKieSessionDeltaEmpty.HASessionDeltaEmptyExternalizer(sessionBuilder)) .addAdvancedExternalizer(new HAKieSessionDeltaFact.HASessionDeltaFactExternalizer(sessionBuilder)) .build(); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.invocationBatching().enable(); configureCacheMode(configurationBuilder, mode, owners); org.infinispan.configuration.cache.Configuration loc = extendDefaultConfiguration(configurationBuilder).build(); return new DefaultCacheManager(glob, loc, true); }
Example #17
Source File: InfinispanKubernetes.java From infinispan-simple-tutorials with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws UnknownHostException { //Configure Infinispan to use default transport and Kubernetes configuration GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().defaultCacheName("defaultCacheName") .transport() .defaultTransport() .addProperty("configurationFile", "default-configs/default-jgroups-kubernetes.xml") .build(); // We need a distributed cache for the purpose of this demo Configuration cacheConfiguration = new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.REPL_SYNC) .build(); DefaultCacheManager cacheManager = new DefaultCacheManager(globalConfig, cacheConfiguration); cacheManager.defineConfiguration("default", cacheConfiguration); Cache<String, String> cache = cacheManager.getCache("default"); //Each cluster member will update its own entry in the cache String hostname = Inet4Address.getLocalHost().getHostName(); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleAtFixedRate(() -> { String time = Instant.now().toString(); cache.put(hostname, time); System.out.println("[" + time + "][" + hostname + "] Values from the cache: "); System.out.println(cache.entrySet()); }, 0, 2, TimeUnit.SECONDS); try { //This container will operate for an hour and then it will die TimeUnit.HOURS.sleep(1); } catch (InterruptedException e) { scheduler.shutdown(); cacheManager.stop(); } }
Example #18
Source File: GlobalConfigurerJmxDisabledConfiguration.java From infinispan-spring-boot with Apache License 2.0 | 5 votes |
@Bean public InfinispanGlobalConfigurer globalConfigurer() { return () -> { final GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder() .transport().clusterName(TEST_CLUSTER) .jmx().disable() .build(); return globalConfiguration; }; }
Example #19
Source File: InfinispanClusterExec.java From infinispan-simple-tutorials with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // Setup up a clustered cache manager GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); // Initialize the cache manager DefaultCacheManager cacheManager = new DefaultCacheManager(global.build()); ClusterExecutor clusterExecutor = cacheManager.executor(); clusterExecutor.submitConsumer(cm -> new Random().nextInt(), (address, intValue, exception) -> System.out.printf("%s\n", intValue)); // Shuts down the cache manager and all associated resources cacheManager.stop(); }
Example #20
Source File: SpringApp.java From infinispan-simple-tutorials with Apache License 2.0 | 5 votes |
@Bean public InfinispanGlobalConfigurer globalCustomizer() { return () -> { GlobalConfigurationBuilder builder = GlobalConfigurationBuilder.defaultClusteredBuilder(); builder.serialization().marshaller(new JavaSerializationMarshaller()); builder.serialization().whiteList().addClass("org.springframework.session.MapSession"); builder.serialization().whiteList().addRegexp("java.util.*"); return builder.build(); }; }
Example #21
Source File: InfinispanCacheTestConfiguration.java From infinispan-spring-boot with Apache License 2.0 | 5 votes |
@Bean public InfinispanGlobalConfigurer globalConfigurer() { return () -> { final GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder() .transport().clusterName(TEST_CLUSTER) .jmx().domain(TEST_GLOBAL_JMX_DOMAIN).enable() .build(); return globalConfiguration; }; }
Example #22
Source File: InvalidationMode.java From infinispan-simple-tutorials with Apache License 2.0 | 4 votes |
public static void main(String[] args) { // Create a clustered configuration and a default cache named test GlobalConfiguration global = GlobalConfigurationBuilder.defaultClusteredBuilder().build(); // Create the cache manager DefaultCacheManager cacheManager = new DefaultCacheManager(global); // Clustered mode invalidation sync. Can also be async Configuration config = new ConfigurationBuilder() .clustering().cacheMode(CacheMode.INVALIDATION_SYNC) .build(); // Define a cache configuration cacheManager.defineConfiguration("test", config); // Retrieve the cache Cache<String, String> cache = cacheManager.getCache("test"); Scanner scanner = new Scanner(System.in); String next = ""; // Enter 'q' option to exit while (!next.equals("q")) { System.out.println( "Invalidation mode simple tutorial\n" + "=================================\n" + "`p` to put a key/value \n" + "`pe` to put a key/value for external read \n" + "`r` to remove a key \n" + "`g` to get a key \n" + "`q` to exit \n"); System.out.println("Enter an option: "); next = scanner.next(); switch (next) { case "p": putKeyValue(scanner, cache); break; case "pe": putForExternalReadKeyValue(scanner, cache); break; case "r": removeKey(scanner, cache); break; case "g": getKey(scanner, cache); break; default: } } // Goodbye! System.out.println("Good bye"); // Stop the cache manager cacheManager.stop(); }
Example #23
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 #24
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; }
Example #25
Source File: InfinispanTest.java From bucket4j with Apache License 2.0 | 4 votes |
private static GlobalConfiguration getGlobalConfiguration() { GlobalConfigurationBuilder globalConfigurationBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder(); globalConfigurationBuilder.serialization().addContextInitializer(new Bucket4jProtobufContextInitializer()); return globalConfigurationBuilder.build(); }
Example #26
Source File: InfinispanITConfiguration.java From spring-batch-lightmin with Apache License 2.0 | 4 votes |
@Bean public GlobalConfiguration globalConfiguration() { return new GlobalConfigurationBuilder() .clusteredDefault() .build(); }
Example #27
Source File: InfinispanCounter.java From infinispan-simple-tutorials with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { // Setup up a clustered cache manager GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); // Create the counter configuration builder CounterManagerConfigurationBuilder builder = global.addModule(CounterManagerConfigurationBuilder.class); // Create 3 counters. // The first counter is bounded to 10 (upper-bound). builder.addStrongCounter().name("counter-1").upperBound(10).initialValue(1); // The second counter is unbounded builder.addStrongCounter().name("counter-2").initialValue(2); // And finally, the third counter is a weak counter. builder.addWeakCounter().name("counter-3").initialValue(3); // Initialize the cache manager DefaultCacheManager cacheManager = new DefaultCacheManager(global.build()); // Retrieve the CounterManager from the CacheManager. Each CacheManager has it own CounterManager CounterManager counterManager = EmbeddedCounterManagerFactory.asCounterManager(cacheManager); // StrongCounter provides the higher consistency. Its value is known during the increment/decrement and it may be bounded. // Bounded counters are aimed for uses cases where a limit is needed. StrongCounter counter1 = counterManager.getStrongCounter("counter-1"); // All methods returns a CompletableFuture. So you can do other work while the counter value is being computed. counter1.getValue().thenAccept(value -> System.out.println("Counter-1 initial value is " + value)).get(); // Try to add more than the upper-bound counter1.addAndGet(10).handle((value, throwable) -> { // Value is null since the counter is bounded and we can add 10 to it. System.out.println("Counter-1 Exception is " + throwable.getMessage()); return 0; }).get(); // Check the counter value. It should be the upper-bound (10) counter1.getValue().thenAccept(value -> System.out.println("Counter-1 value is " + value)).get(); //Decrement the value. Should be 9. counter1.decrementAndGet().handle((value, throwable) -> { // No exception this time. System.out.println("Counter-1 new value is " + value); return value; }).get(); // Similar to counter-1, counter-2 is a strong counter but it is unbounded. It will never throw the CounterOutOfBoundsException StrongCounter counter2 = counterManager.getStrongCounter("counter-2"); // All counters allow a listener to be registered. // The handle can be used to remove the listener counter2.addListener(event -> System.out .println("Counter-2 event: oldValue=" + event.getOldValue() + " newValue=" + event.getNewValue())); // Adding MAX_VALUE won't throws an exception. But the all the increments won't have any effect since we can store //any value larger the MAX_VALUE counter2.addAndGet(Long.MAX_VALUE).thenAccept(aLong -> System.out.println("Counter-2 value is " + aLong)).get(); // Conditional operations are allowed in strong counters counter2.compareAndSet(Long.MAX_VALUE, 0) .thenAccept(aBoolean -> System.out.println("Counter-2 CAS result is " + aBoolean)).get(); counter2.getValue().thenAccept(value -> System.out.println("Counter-2 value is " + value)).get(); // Reset the counter to its initial value (2) counter2.reset().get(); counter2.getValue().thenAccept(value -> System.out.println("Counter-2 initial value is " + value)).get(); // Retrieve counter-3 WeakCounter counter3 = counterManager.getWeakCounter("counter-3"); // Weak counter doesn't have its value available during updates. This makes the increment faster than the StrongCounter // Its value is computed lazily and stored locally. // Its main use case is for uses-case where faster increments are needed. counter3.add(5).thenAccept(aVoid -> System.out.println("Adding 5 to counter-3 completed!")).get(); // Check the counter value. System.out.println("Counter-3 value is " + counter3.getValue()); // Stop the cache manager and release all resources cacheManager.stop(); }
Example #28
Source File: InfinispanClusteredLock.java From infinispan-simple-tutorials with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws InterruptedException { // Setup up a clustered cache manager GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder(); // Initialize 1 cache managers DefaultCacheManager cm = new DefaultCacheManager(global.build()); // Initialize the clustered lock manager from the cache manager ClusteredLockManager clm1 = EmbeddedClusteredLockManagerFactory.from(cm); // Define a lock. By default this lock is non reentrant clm1.defineLock("lock"); // Get a lock interface from each node ClusteredLock lock = clm1.get("lock"); AtomicInteger counter = new AtomicInteger(0); // Acquire and release the lock 3 times CompletableFuture<Boolean> call1 = lock.tryLock(1, TimeUnit.SECONDS).whenComplete((r, ex) -> { if (r) { System.out.println("lock is acquired by the call 1"); lock.unlock().whenComplete((nil, ex2) -> { System.out.println("lock is released by the call 1"); counter.incrementAndGet(); }); } }); CompletableFuture<Boolean> call2 = lock.tryLock(1, TimeUnit.SECONDS).whenComplete((r, ex) -> { if (r) { System.out.println("lock is acquired by the call 2"); lock.unlock().whenComplete((nil, ex2) -> { System.out.println("lock is released by the call 2"); counter.incrementAndGet(); }); } }); CompletableFuture<Boolean> call3 = lock.tryLock(1, TimeUnit.SECONDS).whenComplete((r, ex) -> { if (r) { System.out.println("lock is acquired by the call 3"); lock.unlock().whenComplete((nil, ex2) -> { System.out.println("lock is released by the call 3"); counter.incrementAndGet(); }); } }); CompletableFuture.allOf(call1, call2, call3).whenComplete((r, ex) -> { // Print the value of the counter System.out.println("Value of the counter is " + counter.get()); // Stop the cache manager cm.stop(); }); }
Example #29
Source File: UserSessionsApp.java From infinispan-simple-tutorials with Apache License 2.0 | 4 votes |
@Bean public InfinispanGlobalConfigurer globalCustomizer() { return () -> GlobalConfigurationBuilder.defaultClusteredBuilder().build(); }
Example #30
Source File: AbstractEmbeddedCacheManagerFactory.java From java-platform with Apache License 2.0 | 2 votes |
/** * Sets the {@link GlobalConfigurationBuilder} to use when creating an <code>EmbeddedCacheManager</code>. * * @param gcb the <code>GlobalConfigurationBuilder</code> instance. */ public void addCustomGlobalConfiguration(final GlobalConfigurationBuilder gcb) { this.gcb = gcb; }