org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager Java Examples

The following examples show how to use org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager. 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: SpringCaching.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);
    // Create a cache programmatically for the example. There is no default cache
    EmbeddedCacheManager cacheManager = applicationContext.getBean(SpringEmbeddedCacheManager.class).getNativeCacheManager();
    cacheManager.administration()
          .withFlags(CacheContainerAdmin.AdminFlag.VOLATILE)
          .getOrCreateCache("default", new ConfigurationBuilder().build());

    CachedObject cachePlayground = applicationContext.getBean(CachedObject.class);

    printWithTime(() -> cachePlayground.verySlowMethod());
    printWithTime(() -> cachePlayground.verySlowMethod());
}
 
Example #2
Source File: SpringAnnotationConfiguration.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
    // Create a cache programmatically for the example. There is no default cache
    EmbeddedCacheManager cacheManager = applicationContext.getBean(SpringEmbeddedCacheManager.class).getNativeCacheManager();
    cacheManager.administration()
          .withFlags(CacheContainerAdmin.AdminFlag.VOLATILE)
          .getOrCreateCache("default", new ConfigurationBuilder().build());

    CachePlayground cachePlayground = applicationContext.getBean(CachePlayground.class);

    cachePlayground.add("Infinispan", "Is cool!");
    System.out.println(cachePlayground.getContent("Infinispan"));
}
 
Example #3
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
private Cache<?, ?> getCache(
        final SpringEmbeddedCacheManager springEmbeddedCacheManager,
        final org.infinispan.configuration.cache.Configuration configuration,
        final String cacheName) {
    springEmbeddedCacheManager.getNativeCacheManager().defineConfiguration(cacheName, configuration);

    if (springEmbeddedCacheManager.getNativeCacheManager().isRunning(cacheName)) {
        log.info("Cache {} is already running, nothing to start", cacheName);
    } else {
        springEmbeddedCacheManager.getNativeCacheManager().startCaches(cacheName);
    }
    return springEmbeddedCacheManager.getNativeCacheManager().getCache(cacheName);
}
 
Example #4
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
private org.springframework.cache.Cache getSpringCache(
        final SpringEmbeddedCacheManager springEmbeddedCacheManager,
        final org.infinispan.configuration.cache.Configuration configuration,
        final String cacheName) {
    springEmbeddedCacheManager.getNativeCacheManager().defineConfiguration(cacheName, configuration);

    if (springEmbeddedCacheManager.getNativeCacheManager().isRunning(cacheName)) {
        log.info("Cache {} is already running, nothing to start", cacheName);
    } else {
        springEmbeddedCacheManager.getNativeCacheManager().startCaches(cacheName);
    }
    return springEmbeddedCacheManager.getCache(cacheName);
}
 
Example #5
Source File: InfinispanEmbeddedCacheManagerAutoConfiguration.java    From infinispan-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean(type = {"org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager", "org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManagerFactoryBean"})
@ConditionalOnBean(type = "org.infinispan.manager.EmbeddedCacheManager")
public SpringEmbeddedCacheManager springEmbeddedCacheManager(EmbeddedCacheManager embeddedCacheManager) {
   return new SpringEmbeddedCacheManager(embeddedCacheManager);
}
 
Example #6
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 4 votes vote down vote up
@Bean(name = INFINISPAN_DEFAULT_CACHE_MANAGER_NAME)
@ConditionalOnMissingBean(SpringEmbeddedCacheManager.class)
public SpringEmbeddedCacheManager infinispanCacheManager(final GlobalConfiguration globalConfiguration) {
    final EmbeddedCacheManager manager = new DefaultCacheManager(globalConfiguration);
    return new SpringEmbeddedCacheManager(manager);
}
 
Example #7
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 4 votes vote down vote up
@Bean
@DependsOn(value = {VERIFICATION_CACHE_NAME})
public LightminServerLockManager lightminServerLockManager(final SpringEmbeddedCacheManager springEmbeddedCacheManager) {
    return new InfinispanLightminServerLockManager(springEmbeddedCacheManager.getNativeCacheManager());
}
 
Example #8
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 4 votes vote down vote up
@Bean(name = REPOSITORY_ID_CACHE_NAME)
public org.springframework.cache.Cache lightminRepositoryIdCache(final SpringEmbeddedCacheManager springEmbeddedCacheManager) {
    final org.infinispan.configuration.cache.Configuration configuration = this.getConfiguration();
    return this.getSpringCache(springEmbeddedCacheManager, configuration, REPOSITORY_ID_CACHE_NAME);
}
 
Example #9
Source File: InfinispanServerClusterConfiguration.java    From spring-batch-lightmin with Apache License 2.0 3 votes vote down vote up
@Bean(name = VERIFICATION_CACHE_NAME)
public org.springframework.cache.Cache lightminLockVerificationCache(final SpringEmbeddedCacheManager springEmbeddedCacheManager) {

    final org.infinispan.configuration.cache.Configuration configuration = this.getConfiguration();

    return this.getSpringCache(springEmbeddedCacheManager, configuration, VERIFICATION_CACHE_NAME);
}