org.infinispan.configuration.cache.ConfigurationBuilder Java Examples

The following examples show how to use org.infinispan.configuration.cache.ConfigurationBuilder. 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: 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 #2
Source File: InfinispanEmbeddedProducer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that if a configuration has transactions enabled that it only uses the lookup that uses the
 * JBossStandaloneJTAManager, which looks up the transaction manager used by Quarkus
 * 
 * @param configurationBuilder the current configuration
 * @param cacheName the cache for the configuration
 */
private void verifyTransactionConfiguration(ConfigurationBuilder configurationBuilder, String cacheName) {
    TransactionConfigurationBuilder transactionConfigurationBuilder = configurationBuilder.transaction();
    if (transactionConfigurationBuilder.transactionMode() != null
            && transactionConfigurationBuilder.transactionMode().isTransactional()) {
        AttributeSet attributes = transactionConfigurationBuilder.attributes();
        Attribute<TransactionManagerLookup> managerLookup = attributes
                .attribute(TransactionConfiguration.TRANSACTION_MANAGER_LOOKUP);
        if (managerLookup.isModified() && !(managerLookup.get() instanceof JBossStandaloneJTAManagerLookup)) {
            throw new CacheConfigurationException(
                    "Only JBossStandaloneJTAManagerLookup transaction manager lookup is supported. Cache " + cacheName
                            + " is misconfigured!");
        }
        managerLookup.set(new JBossStandaloneJTAManagerLookup());
    }
}
 
Example #3
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 #4
Source File: InfinispanEmbeddedProducer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Singleton
@Produces
EmbeddedCacheManager manager() {
    if (config.xmlConfig.isPresent()) {
        String configurationFile = config.xmlConfig.get();
        try {
            InputStream configurationStream = FileLookupFactory.newInstance().lookupFileStrict(configurationFile,
                    Thread.currentThread().getContextClassLoader());
            ConfigurationBuilderHolder configHolder = new ParserRegistry().parse(configurationStream, null);
            verifyTransactionConfiguration(configHolder.getDefaultConfigurationBuilder(), "default");
            for (Map.Entry<String, ConfigurationBuilder> entry : configHolder.getNamedConfigurationBuilders().entrySet()) {
                verifyTransactionConfiguration(entry.getValue(), entry.getKey());
            }
            return new DefaultCacheManager(configHolder, true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return new DefaultCacheManager();
}
 
Example #5
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 #6
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 #7
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 #8
Source File: DefaultInfinispanConnectionProviderFactory.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void configureRemoteActionTokenCacheStore(ConfigurationBuilder builder, boolean async) {
    String jdgServer = config.get("remoteStoreHost", "localhost");
    Integer jdgPort = config.getInt("remoteStorePort", 11222);

    builder.persistence()
            .passivation(false)
            .addStore(RemoteStoreConfigurationBuilder.class)
                .fetchPersistentState(false)
                .ignoreModifications(false)
                .purgeOnStartup(false)
                .preload(true)
                .shared(true)
                .remoteCacheName(InfinispanConnectionProvider.ACTION_TOKEN_CACHE)
                .rawValues(true)
                .forceReturnValues(false)
                .marshaller(KeycloakHotRodMarshallerFactory.class.getName())
                .protocolVersion(getHotrodVersion())
                .addServer()
                    .host(jdgServer)
                    .port(jdgPort)
                .async()
                    .enabled(async);

}
 
Example #9
Source File: InfinispanEmbeddedCacheConfig.java    From spring4-sandbox with Apache License 2.0 6 votes vote down vote up
@Override
@Bean
public CacheManager cacheManager() {

	return new SpringEmbeddedCacheManager(
			new DefaultCacheManager(
				new ConfigurationBuilder()
					.eviction()
						.maxEntries(20000)
						.strategy(EvictionStrategy.LIRS)
					.expiration()
						.wakeUpInterval(5000L)
						.maxIdle(120000L)
		           .build()
				)
			);
}
 
Example #10
Source File: InfinispanServerExtension.java    From infinispan-spring-boot with Apache License 2.0 6 votes vote down vote up
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 #11
Source File: InfinispanCacheFactory.java    From cache2k-benchmark with Apache License 2.0 6 votes vote down vote up
@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 #12
Source File: InfinispanCacheTestConfiguration.java    From infinispan-spring-boot with Apache License 2.0 6 votes vote down vote up
@Bean
public InfinispanCacheConfigurer cacheConfigurer() {
   return cacheManager -> {
      final org.infinispan.configuration.cache.ConfigurationBuilder testCacheBuilder = new ConfigurationBuilder();

      testCacheBuilder.simpleCache(true)
            .memory()
            .storageType(StorageType.OBJECT)
            .evictionType(EvictionType.COUNT)
            .evictionStrategy(EvictionStrategy.MANUAL);

      testCacheBuilder.statistics().enable();

      cacheManager.defineConfiguration(TEST_CACHE_NAME, testCacheBuilder.build());
   };
}
 
Example #13
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 #14
Source File: InfinispanTest.java    From bucket4j with Apache License 2.0 6 votes vote down vote up
@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 #15
Source File: InfinispanDistributed.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 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 #16
Source File: InfinispanListen.java    From infinispan-simple-tutorials with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
   // Construct a simple local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   // Define local cache configuration
   cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
   // Obtain the local cache
   Cache<String, String> cache = cacheManager.getCache("local");
   // Register a listener
   cache.addListener(new MyListener());
   // Store some values
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   cache.put("key1", "newValue");
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
Example #17
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 #18
Source File: InfinispanStreams.java    From infinispan-simple-tutorials with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
   // Construct a simple local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   // Define local cache configuration
   cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
   // Obtain the local cache
   Cache<String, String> cache = cacheManager.getCache("local");
   // Store some values
   int range = 10;
   IntStream.range(0, range).boxed().forEach(i -> cache.put(i + "-key", i + "-value"));
   // Map and reduce the keys
   int result = cache.keySet().stream()
         .map(e -> Integer.valueOf(e.substring(0, e.indexOf("-"))))
         .collect(() -> Collectors.summingInt(i -> i.intValue()));
   System.out.printf("Result = %d\n", result);
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
Example #19
Source File: DefaultInfinispanConnectionProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void configureRemoteCacheStore(ConfigurationBuilder builder, boolean async, String cacheName, boolean sessionCache) {
        String jdgServer = config.get("remoteStoreHost", "localhost");
        Integer jdgPort = config.getInt("remoteStorePort", 11222);

        builder.persistence()
                .passivation(false)
                .addStore(RemoteStoreConfigurationBuilder.class)
                    .fetchPersistentState(false)
                    .ignoreModifications(false)
                    .purgeOnStartup(false)
                    .preload(false)
                    .shared(true)
                    .remoteCacheName(cacheName)
                    .rawValues(true)
                    .forceReturnValues(false)
                    .marshaller(KeycloakHotRodMarshallerFactory.class.getName())
                    .protocolVersion(getHotrodVersion())
                    .addServer()
                        .host(jdgServer)
                        .port(jdgPort)
//                  .connectionPool()
//                      .maxActive(100)
//                      .exhaustedAction(ExhaustedAction.CREATE_NEW)
                    .async()
                        .enabled(async);

    }
 
Example #20
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 #21
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 #22
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 #23
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
protected org.infinispan.configuration.cache.Configuration getConfiguration() {
    return new ConfigurationBuilder()
            .clustering()
            .cacheMode(CacheMode.REPL_SYNC)
            .stateTransfer()
            .awaitInitialTransfer(Boolean.FALSE)
            .jmxStatistics()
            .enable()
            .build();
}
 
Example #24
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
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 #25
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 #26
Source File: InfinispanMultimap.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
   // Construct a local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager();

   // Obtain a multimap cache manager from the regular cache manager
   MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cacheManager);

   // Define de multimap cache configuration, as a regular cache
   multimapCacheManager.defineConfiguration("multimap", new ConfigurationBuilder().build());

   // Get the MultimapCache
   MultimapCache<String, String> multimap = multimapCacheManager.get("multimap");

   // Store multiple values in a key
   CompletableFuture.allOf(
         multimap.put("key", "value1"),
         multimap.put("key", "value2"),
         multimap.put("key", "value3"))
         .whenComplete((nil, ex) -> {
            // Retrieve the values
            multimap.get("key").whenComplete((values, ex2) -> {
               // Print them out
               System.out.println(values);
               // Stop the cache manager and release all resources
               cacheManager.stop();
            });
         });
}
 
Example #27
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 #28
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 #29
Source File: InfinispanRegistryStorage.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@Override
protected void afterInit() {
    manager.defineConfiguration(
            COUNTER_CACHE,
            new ConfigurationBuilder()
                    .clustering().cacheMode(CacheMode.REPL_SYNC)
                    .build()
    );

    counter = manager.getCache(COUNTER_CACHE, true);
}
 
Example #30
Source File: ClusterManager.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@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));
}