org.infinispan.configuration.cache.CacheMode Java Examples
The following examples show how to use
org.infinispan.configuration.cache.CacheMode.
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: 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 #3
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 #4
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 #5
Source File: InfinispanTest.java From bucket4j with Apache License 2.0 | 6 votes |
@BeforeClass public static void init() throws MalformedURLException, URISyntaxException { cacheManager1 = new DefaultCacheManager(getGlobalConfiguration()); cacheManager1.defineConfiguration("my-cache", new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.DIST_SYNC) .hash().numOwners(2) .build() ); cache = cacheManager1.getCache("my-cache"); readWriteMap = toMap(cache); cacheManager2 = new DefaultCacheManager(getGlobalConfiguration()); cacheManager2.defineConfiguration("my-cache", new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.DIST_SYNC) .hash().numOwners(2) .build() ); cacheManager2.getCache("my-cache"); }
Example #6
Source File: ClusterManager.java From glowroot with Apache License 2.0 | 5 votes |
@Override public <K extends /*@NonNull*/ Serializable, V extends /*@NonNull*/ Serializable> ConcurrentMap<K, V> createReplicatedMap( String mapName, long expirationTime, TimeUnit expirationUnit) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.clustering() .cacheMode(CacheMode.REPL_ASYNC) .expiration() .lifespan(expirationTime, expirationUnit) .jmxStatistics() .enable(); cacheManager.defineConfiguration(mapName, configurationBuilder.build()); return cacheManager.getCache(mapName); }
Example #7
Source File: SpringApp.java From infinispan-simple-tutorials with Apache License 2.0 | 5 votes |
@Bean public InfinispanCacheConfigurer cacheConfigurer() { return manager -> { final Configuration ispnConfig = new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.DIST_SYNC) .build(); manager.defineConfiguration("sessions", ispnConfig); }; }
Example #8
Source File: UserSessionsApp.java From infinispan-simple-tutorials with Apache License 2.0 | 5 votes |
@Bean public InfinispanCacheConfigurer cacheConfigurer() { return manager -> { final Configuration ispnConfig = new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.DIST_SYNC) .build(); manager.defineConfiguration("sessions", ispnConfig); }; }
Example #9
Source File: InfinispanServerClusterConfiguration.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
protected org.infinispan.configuration.cache.Configuration getConfiguration(final Long limit) { return new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.REPL_SYNC) .stateTransfer() .awaitInitialTransfer(Boolean.FALSE) .jmxStatistics() .enable() .eviction() .type(EvictionType.COUNT) .size(limit) .build(); }
Example #10
Source File: InfinispanServerClusterConfiguration.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
protected org.infinispan.configuration.cache.Configuration getConfiguration() { return new ConfigurationBuilder() .clustering() .cacheMode(CacheMode.REPL_SYNC) .stateTransfer() .awaitInitialTransfer(Boolean.FALSE) .jmxStatistics() .enable() .build(); }
Example #11
Source File: ClusterManager.java From glowroot with Apache License 2.0 | 5 votes |
@Override public <K extends /*@NonNull*/ Serializable, V extends /*@NonNull*/ Object> Cache<K, V> createSelfBoundedCache( String cacheName, CacheLoader<K, V> loader) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.clustering() .cacheMode(CacheMode.INVALIDATION_ASYNC) .jmxStatistics() .enable(); cacheManager.defineConfiguration(cacheName, configurationBuilder.build()); return new CacheImpl<K, V>(cacheManager.getCache(cacheName), loader); }
Example #12
Source File: InfinispanRegistryStorage.java From apicurio-registry with Apache License 2.0 | 5 votes |
@Override protected StorageMap createStorageMap() { manager.defineConfiguration( STORAGE_CACHE, new ConfigurationBuilder() .clustering().cacheMode(CacheMode.REPL_SYNC) .build() ); Cache<String, Map<Long, Map<String, String>>> cache = manager.getCache(STORAGE_CACHE, true); return CacheStorageMap.create(cache); }
Example #13
Source File: ClusterManager.java From glowroot with Apache License 2.0 | 5 votes |
@Override public <K extends /*@NonNull*/ Serializable, V extends /*@NonNull*/ Object> DistributedExecutionMap<K, V> createDistributedExecutionMap( String cacheName) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.clustering() .cacheMode(CacheMode.LOCAL) .jmxStatistics() .enable(); cacheManager.defineConfiguration(cacheName, configurationBuilder.build()); return new DistributedExecutionMapImpl<K, V>(cacheManager.getCache(cacheName)); }
Example #14
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 #15
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 #16
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 #17
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 #18
Source File: DeviceConnectionCacheProvider.java From enmasse with Apache License 2.0 | 5 votes |
public org.infinispan.configuration.cache.Configuration buildConfiguration() { return new org.infinispan.configuration.cache.ConfigurationBuilder() .indexing() .index(Index.NONE) .clustering() .cacheMode(CacheMode.DIST_SYNC) .hash() .numOwners(1) .build(); }
Example #19
Source File: DeviceManagementCacheProvider.java From enmasse with Apache License 2.0 | 5 votes |
public org.infinispan.configuration.cache.Configuration buildAdapterCredentialsConfiguration() { return new org.infinispan.configuration.cache.ConfigurationBuilder() .indexing() .index(Index.NONE) .clustering() .cacheMode(CacheMode.DIST_SYNC) .hash() .numOwners(1) .build(); }
Example #20
Source File: DeviceManagementCacheProvider.java From enmasse with Apache License 2.0 | 5 votes |
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 #21
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 #22
Source File: DataGridManager.java From hacep with Apache License 2.0 | 5 votes |
private CacheMode getCacheMode() { try { return CacheMode.valueOf(System.getProperty("grid.mode", "DIST_SYNC")); } catch (IllegalArgumentException e) { return CacheMode.DIST_SYNC; } }
Example #23
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 #24
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 #25
Source File: InfinispanRegistryStorage.java From apicurio-registry with Apache License 2.0 | 5 votes |
/** * @see io.apicurio.registry.storage.impl.AbstractMapRegistryStorage#createArtifactRulesMap() */ @SuppressWarnings({"rawtypes", "unchecked"}) @Override protected MultiMap<String, String, String> createArtifactRulesMap() { manager.defineConfiguration( ARTIFACT_RULES_CACHE, new ConfigurationBuilder() .clustering().cacheMode(CacheMode.REPL_SYNC) .build() ); Cache<String, MapValue<String, String>> cache = manager.getCache(ARTIFACT_RULES_CACHE, true); return new CacheMultiMap<>(cache); }
Example #26
Source File: InfinispanRegistryStorage.java From apicurio-registry with Apache License 2.0 | 5 votes |
/** * @see io.apicurio.registry.storage.impl.AbstractMapRegistryStorage#createGlobalRulesMap() */ @Override protected Map<String, String> createGlobalRulesMap() { manager.defineConfiguration( GLOBAL_RULES_CACHE, new ConfigurationBuilder() .clustering().cacheMode(CacheMode.REPL_SYNC) .build() ); return manager.getCache(GLOBAL_RULES_CACHE, true); }
Example #27
Source File: InfinispanRegistryStorage.java From apicurio-registry with Apache License 2.0 | 5 votes |
@Override protected void afterInit() { manager.defineConfiguration( COUNTER_CACHE, new ConfigurationBuilder() .clustering().cacheMode(CacheMode.REPL_SYNC) .build() ); counter = manager.getCache(COUNTER_CACHE, true); }
Example #28
Source File: InfinispanRegistryStorage.java From apicurio-registry with Apache License 2.0 | 5 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) @Override protected Map<Long, TupleId> createGlobalMap() { manager.defineConfiguration( GLOBAL_CACHE, new ConfigurationBuilder() .clustering().cacheMode(CacheMode.REPL_SYNC) .build() ); return manager.getCache(GLOBAL_CACHE, true); }
Example #29
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 #30
Source File: InfinispanSessionCacheIdMapperUpdater.java From keycloak with Apache License 2.0 | 4 votes |
public static SessionIdMapperUpdater addTokenStoreUpdaters(ServletContext servletContext, SessionIdMapper mapper, SessionIdMapperUpdater previousIdMapperUpdater) { String containerName = servletContext.getInitParameter(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME); String cacheName = servletContext.getInitParameter(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME); // the following is based on https://github.com/jbossas/jboss-as/blob/7.2.0.Final/clustering/web-infinispan/src/main/java/org/jboss/as/clustering/web/infinispan/DistributedCacheManagerFactory.java#L116-L122 String contextPath = servletContext.getContextPath(); if (contextPath == null || contextPath.isEmpty() || "/".equals(contextPath)) { contextPath = "/ROOT"; } String deploymentSessionCacheName = contextPath; if (containerName == null || cacheName == null) { LOG.warnv("Cannot determine parameters of SSO cache for deployment {0}.", contextPath); return previousIdMapperUpdater; } String cacheContainerLookup = DEFAULT_CACHE_CONTAINER_JNDI_NAME + "/" + containerName; try { EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) new InitialContext().lookup(cacheContainerLookup); Configuration ssoCacheConfiguration = cacheManager.getCacheConfiguration(cacheName); if (ssoCacheConfiguration == null) { Configuration cacheConfiguration = cacheManager.getCacheConfiguration(deploymentSessionCacheName); if (cacheConfiguration == null) { LOG.debugv("Using default configuration for SSO cache {0}.{1}.", containerName, cacheName); ssoCacheConfiguration = cacheManager.getDefaultCacheConfiguration(); } else { LOG.debugv("Using distributed HTTP session cache configuration for SSO cache {0}.{1}, configuration taken from cache {2}", containerName, cacheName, deploymentSessionCacheName); ssoCacheConfiguration = cacheConfiguration; cacheManager.defineConfiguration(cacheName, ssoCacheConfiguration); } } else { LOG.debugv("Using custom configuration of SSO cache {0}.{1}.", containerName, cacheName); } CacheMode ssoCacheMode = ssoCacheConfiguration.clustering().cacheMode(); if (ssoCacheMode != CacheMode.REPL_ASYNC && ssoCacheMode != CacheMode.REPL_SYNC) { LOG.warnv("SSO cache mode is {0}, it is recommended to use replicated mode instead.", ssoCacheConfiguration.clustering().cacheModeString()); } Cache<String, String[]> ssoCache = cacheManager.getCache(cacheName, true); final SsoSessionCacheListener listener = new SsoSessionCacheListener(ssoCache, mapper); ssoCache.addListener(listener); addSsoCacheCrossDcListener(ssoCache, listener); LOG.debugv("Added distributed SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName); SsoCacheSessionIdMapperUpdater updater = new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater) { @Override public void close() throws Exception { ssoCache.stop(); } }; return updater; } catch (NamingException ex) { LOG.warnv("Failed to obtain distributed session cache container, lookup={0}", cacheContainerLookup); return previousIdMapperUpdater; } }