Java Code Examples for org.infinispan.manager.EmbeddedCacheManager#defineConfiguration()
The following examples show how to use
org.infinispan.manager.EmbeddedCacheManager#defineConfiguration() .
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: InfinispanCacheFactory.java From cache2k-benchmark with Apache License 2.0 | 6 votes |
@Override protected <K, V> BenchmarkCache<K, V> createSpecialized(final Class<K> _keyType, final Class<V> _valueType, final int _maxElements) { EmbeddedCacheManager m = getCacheMangaer(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.eviction().maxEntries(_maxElements); cb.storeAsBinary().disable(); if (!withExpiry) { cb.expiration().disableReaper().lifespan(-1); } else { cb.expiration().lifespan(5 * 60, TimeUnit.SECONDS); } switch (algorithm) { case LRU: cb.eviction().strategy(EvictionStrategy.LRU); break; case LIRS: cb.eviction().strategy(EvictionStrategy.LIRS); break; case UNORDERED: cb.eviction().strategy(EvictionStrategy.UNORDERED); break; } m.defineConfiguration(CACHE_NAME, cb.build()); Cache<Integer, Integer> _cache = m.getCache(CACHE_NAME); return new MyBenchmarkCache(_cache); }
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: 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: 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 5
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 6
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 7
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 8
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 9
Source File: InfinispanSessionCacheIdMapperUpdater.java From keycloak with Apache License 2.0 | 4 votes |
public static SessionIdMapperUpdater addTokenStoreUpdaters(Context context, SessionIdMapper mapper, SessionIdMapperUpdater previousIdMapperUpdater) { ServletContext servletContext = context.getServletContext(); String containerName = servletContext == null ? null : servletContext.getInitParameter(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME); String cacheName = servletContext == null ? null : 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 host = context.getParent() == null ? "" : context.getParent().getName(); String contextPath = context.getPath(); if ("/".equals(contextPath)) { contextPath = "/ROOT"; } String deploymentSessionCacheName = host + contextPath; if (containerName == null || cacheName == null || deploymentSessionCacheName == null) { LOG.warnv("Cannot determine parameters of SSO cache for deployment {0}.", host + 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); // Not possible to add listener for cross-DC support because of too old Infinispan in AS 7 warnIfRemoteStoreIsUsed(ssoCache); LOG.debugv("Added distributed SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName); SsoCacheSessionIdMapperUpdater updater = new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater); return updater; } catch (NamingException ex) { LOG.warnv("Failed to obtain distributed session cache container, lookup={0}", cacheContainerLookup); return previousIdMapperUpdater; } }
Example 10
Source File: InfinispanSessionCacheIdMapperUpdater.java From keycloak with Apache License 2.0 | 4 votes |
public static SessionIdMapperUpdater addTokenStoreUpdaters(DeploymentInfo deploymentInfo, SessionIdMapper mapper, SessionIdMapperUpdater previousIdMapperUpdater) { Map<String, String> initParameters = deploymentInfo.getInitParameters(); String containerName = initParameters == null ? null : initParameters.get(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME); String cacheName = initParameters == null ? null : initParameters.get(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME); if (containerName == null || cacheName == null) { LOG.warnv("Cannot determine parameters of SSO cache for deployment {0}.", deploymentInfo.getDeploymentName()); return previousIdMapperUpdater; } String cacheContainerLookup = DEFAULT_CACHE_CONTAINER_JNDI_NAME + "/" + containerName; String deploymentSessionCacheName = deploymentInfo.getDeploymentName(); 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); LOG.debugv("Adding session listener for SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName); SsoCacheSessionIdMapperUpdater updater = new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater); deploymentInfo.addSessionListener(updater); return updater; } catch (NamingException ex) { LOG.warnv("Failed to obtain distributed session cache container, lookup={0}", cacheContainerLookup); return previousIdMapperUpdater; } }
Example 11
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; } }