org.infinispan.configuration.cache.Configuration Java Examples

The following examples show how to use org.infinispan.configuration.cache.Configuration. 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: L1SerializationIssueTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: DefaultInfinispanConnectionProviderFactory.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private Configuration getRevisionCacheConfig(long maxEntries) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.invocationBatching().enable().transaction().transactionMode(TransactionMode.TRANSACTIONAL);

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

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

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

    return cb.build();
}
 
Example #3
Source File: InfinispanReplicated.java    From infinispan-simple-tutorials with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: InfinispanKeyStorageProviderTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: ConcurrencyLockingTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: ClusterManager.java    From glowroot with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: TestCacheManagerFactory.java    From keycloak with Apache License 2.0 6 votes vote down vote up
<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 #8
Source File: CacheConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
private <K, V> Cache<K, V> buildCache(String cacheName, DefaultCacheManager cacheManager, CacheListener listener, Configuration configuration) {

        cacheManager.defineConfiguration(cacheName, configuration);
        Cache<K, V> cache = cacheManager.getCache(cacheName);
        cache.addListener(listener);
        return cache;
    }
 
Example #9
Source File: ReplicatedServerWithMaster.java    From unitime with Apache License 2.0 5 votes vote down vote up
private <U,T> Cache<U,T> getCache(String name) {
	Configuration config = iCacheManager.getCacheConfiguration(name);
	if (config != null) {
		iLog.info("Using " + config + " for " + name + " cache.");
		iCacheManager.defineConfiguration(cacheName(name), config);
	}
	return iCacheManager.getCache(cacheName(name), true);
}
 
Example #10
Source File: ReplicatedServer.java    From unitime with Apache License 2.0 5 votes vote down vote up
private <U,T> Cache<U,T> getCache(String name) {
	Configuration config = iCacheManager.getCacheConfiguration(name);
	if (config != null) {
		iLog.info("Using " + config + " for " + name + " cache.");
		iCacheManager.defineConfiguration(cacheName(name), config);
	}
	return iCacheManager.getCache(cacheName(name), true);
}
 
Example #11
Source File: InfinispanFactory.java    From pippo with Apache License 2.0 5 votes vote down vote up
/**
 * Create cache manager with custom idle time.
 *
 * @param idleTime idle time in seconds
 * @return cache manager
 */
public static EmbeddedCacheManager create(long idleTime) {
    Configuration configuration = new ConfigurationBuilder()
            .expiration().maxIdle(idleTime, TimeUnit.SECONDS)
            .build();
    return new DefaultCacheManager(configuration);
}
 
Example #12
Source File: InfinispanCacheFactory.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map<CacheCategory, CacheService> createCaches(CacheInfo cacheInfo) {
	Map<CacheCategory, CacheService> ciCaches = new HashMap<CacheCategory, CacheService>();
	for (Map.Entry<CacheCategory, CacheConfiguration> entry : cacheInfo.getConfiguration().entrySet()) {
		if (entry.getValue() instanceof InfinispanConfiguration) {
			CacheService cacheService;
			CacheCategory category = entry.getKey();
			InfinispanConfiguration config = (InfinispanConfiguration) entry.getValue();
			if (config.isCacheEnabled()) {
				String configurationName = config.getConfigurationName();
				if (null == configurationName) {
					Configuration dcc = manager.getDefaultCacheConfiguration();
					Configuration infinispan = config.getInfinispanConfiguration(
							new ConfigurationBuilder().read(dcc));
					configurationName = "$" + category.getName() + "$" + cacheInfo.getId();
					manager.defineConfiguration(configurationName, infinispan);
				}
				recorder.record("infinispan", "configuration name " + configurationName);
				Cache<String, Object> cache = manager.<String, Object>getCache(configurationName);
				cache.addListener(listener);
				cacheService = new InfinispanCacheService(cache);
			} else {
				cacheService = noCacheFactory.create(null, category);
			}
			ciCaches.put(category, cacheService);
		}
	}
	return ciCaches;
}
 
Example #13
Source File: SpringApp.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
@Bean
public InfinispanCacheConfigurer cacheConfigurer() {
   return manager -> {
      final Configuration ispnConfig = new ConfigurationBuilder()
            .clustering()
            .cacheMode(CacheMode.DIST_SYNC)
            .build();


      manager.defineConfiguration("sessions", ispnConfig);
   };
}
 
Example #14
Source File: ConcurrencyVersioningTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected DefaultCacheManager getVersionedCacheManager() {
    GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder();


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

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

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


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

    if (clustered) {
        invalidationConfigBuilder.clustering().cacheMode(async ? CacheMode.INVALIDATION_ASYNC : CacheMode.INVALIDATION_SYNC);
    }
    Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build();
    cacheManager.defineConfiguration(InfinispanConnectionProvider.REALM_CACHE_NAME, invalidationCacheConfiguration);
    return cacheManager;
}
 
Example #15
Source File: OutdatedTopologyExceptionReproducerTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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: ClusteredCacheBehaviorTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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 #17
Source File: DefaultInfinispanConnectionProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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 #18
Source File: UserSessionsApp.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
@Bean
public InfinispanCacheConfigurer cacheConfigurer() {
    return manager -> {
        final Configuration ispnConfig = new ConfigurationBuilder()
                .clustering()
                .cacheMode(CacheMode.DIST_SYNC)
                .build();


        manager.defineConfiguration("sessions", ispnConfig);
    };
}
 
Example #19
Source File: InfinispanKubernetes.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
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 #20
Source File: DistributedCacheConcurrentWritesTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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 #21
Source File: InfinispanTx.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   // Construct a local cache manager
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   // Create a transaction cache config
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL);
   Configuration cacheConfig = builder.build();
   // Create a cache with the config
   Cache<String, String> cache = cacheManager.administration()
           .withFlags(CacheContainerAdmin.AdminFlag.VOLATILE)
           .getOrCreateCache("cache", cacheConfig);
   // Obtain the transaction manager
   TransactionManager transactionManager = cache.getAdvancedCache().getTransactionManager();
   // Perform some operations within a transaction and commit it
   transactionManager.begin();
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   transactionManager.commit();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Perform some operations within a transaction and roll it back
   transactionManager.begin();
   cache.put("key1", "value3");
   cache.put("key2", "value4");
   transactionManager.rollback();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
Example #22
Source File: DistributedCacheConcurrentWritesTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static BasicCache<String, SessionEntityWrapper<UserSessionEntity>> createRemoteCache(String nodeName) {
    int port = ("node1".equals(nodeName)) ? 12232 : 13232;

    org.infinispan.client.hotrod.configuration.ConfigurationBuilder builder = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder();
    org.infinispan.client.hotrod.configuration.Configuration cfg = builder
            .addServer().host("localhost").port(port)
            .version(ProtocolVersion.PROTOCOL_VERSION_26)
            .build();
    RemoteCacheManager mgr = new RemoteCacheManager(cfg);
    return mgr.getCache(InfinispanConnectionProvider.USER_SESSION_CACHE_NAME);
}
 
Example #23
Source File: InfinispanEmbeddedAutoConfigurationIntegrationConfigurerTest.java    From infinispan-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithCacheConfigurer() {
   assertThat(defaultCacheManager.getCacheNames()).containsExactlyInAnyOrder(InfinispanCacheTestConfiguration.TEST_CACHE_NAME, "default");

   final Configuration testCacheConfiguration = defaultCacheManager.getCacheConfiguration(InfinispanCacheTestConfiguration.TEST_CACHE_NAME);
   assertThat(testCacheConfiguration.statistics().enabled()).isTrue();
   assertThat(testCacheConfiguration.memory().storageType()).isEqualTo(StorageType.OBJECT);
   assertThat(testCacheConfiguration.memory().evictionType()).isEqualTo(EvictionType.COUNT);
   assertThat(testCacheConfiguration.memory().evictionStrategy()).isEqualTo(EvictionStrategy.MANUAL);
}
 
Example #24
Source File: InfinispanEmbeddedAutoConfigurationIntegrationTest.java    From infinispan-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConfigurations() {
   assertThat(defaultCacheManager.getClusterName()).isEqualTo("default-autoconfigure");
   assertThat(defaultCacheManager.getCacheNames()).containsExactly("default");

   final Configuration defaultCacheConfiguration = defaultCacheManager.getDefaultCacheConfiguration();
   assertThat(defaultCacheConfiguration).isNull();

   final GlobalConfiguration globalConfiguration = defaultCacheManager.getCacheManagerConfiguration();
   assertThat(globalConfiguration.jmx().enabled()).isTrue();
   assertThat(globalConfiguration.jmx().domain()).isEqualTo("org.infinispan");
}
 
Example #25
Source File: InfinispanEmbeddedAutoConfigurationPropertiesTest.java    From infinispan-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void testCacheManagerXmlConfig() {
   assertThat(defaultCacheManager.getCacheNames()).isEqualTo(Collections.singleton("default-local"));

   final GlobalConfiguration globalConfiguration = defaultCacheManager.getCacheManagerConfiguration();
   assertThat(globalConfiguration.globalJmxStatistics().enabled()).isTrue();
   assertThat(globalConfiguration.globalJmxStatistics().domain()).isEqualTo("properties.test.spring.infinispan");

   final Configuration defaultCacheConfiguration = defaultCacheManager.getDefaultCacheConfiguration();
   assertThat(defaultCacheConfiguration.memory().size()).isEqualTo(2000L);
}
 
Example #26
Source File: TestCacheManagerFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private <T extends StoreConfigurationBuilder<?, T> & RemoteStoreConfigurationChildBuilder<T>> Configuration getCacheBackedByRemoteStore(int threadId, String cacheName, Class<T> builderClass) {
    ConfigurationBuilder cacheConfigBuilder = new ConfigurationBuilder();

    String host = "localhost";
    int port = threadId==1 ? 12232 : 13232;
    //int port = 11222;

    return cacheConfigBuilder.persistence().addStore(builderClass)
            .fetchPersistentState(false)
            .ignoreModifications(false)
            .purgeOnStartup(false)
            .preload(false)
            .shared(true)
            .remoteCacheName(cacheName)
            .rawValues(true)
            .forceReturnValues(false)
            .marshaller(KeycloakHotRodMarshallerFactory.class.getName())
            //.protocolVersion(ProtocolVersion.PROTOCOL_VERSION_26)
            //.maxBatchSize(5)
            .addServer()
                .host(host)
                .port(port)
            .connectionPool()
                .maxActive(20)
                .exhaustedAction(ExhaustedAction.CREATE_NEW)
            .async()
            .   enabled(false).build();
}
 
Example #27
Source File: DataGridManager.java    From hacep with Apache License 2.0 5 votes vote down vote up
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 #28
Source File: SubstituteDefaultCacheManager.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Substitute
public SubstituteDefaultCacheManager(Configuration defaultConfiguration, boolean start) {
    throw new RuntimeException("DefaultCacheManager not supported in native image mode");
}
 
Example #29
Source File: DistributedCacheWriteSkewTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
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 #30
Source File: InfinispanSessionCacheIdMapperUpdater.java    From keycloak with Apache License 2.0 4 votes vote down vote up
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;
    }
}