All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.spring.AbstractEmbeddedCacheManagerFactory Maven / Gradle / Ivy

Go to download

The Infinispan Spring Integration project provides Spring integration for Infinispan, a high performance distributed cache. Its primary features are * An implementation of org.springframework.cache.CacheManager, Spring's central caching abstraction, backed by Infinispan's EmbeddedCacheManager. To be used if your Spring-powered application and Infinispan are colocated, i.e. running within the same VM. * An implementation of org.springframework.cache.CacheManager backed by Infinispan's RemoteCacheManager. To bes used if your Spring-powered application accesses Infinispan remotely, i.e. over the network. * An implementation of org.springframework.cache.CacheManager backed by a CacheContainer reference. To be used if your Spring- powered application needs access to a CacheContainer defined outside the application (e.g. retrieved from JNDI) * Spring namespace support allowing shortcut definitions for all the components above In addition, Infinispan Spring Integration offers various FactoryBeans for facilitating creation of Infinispan core classes - Cache, CacheManager, ... - within a Spring context.

There is a newer version: 8.1.0.Alpha2
Show newest version
package org.infinispan.spring;

import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
import org.infinispan.configuration.parsing.ParserRegistry;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import org.springframework.core.io.Resource;

import java.io.IOException;

/**
 * 

* An abstract base class for factories creating cache managers that are backed by an * EmbeddedCacheManager. *

* * @author Olaf Bergner * @author Marius Bogoevici */ public class AbstractEmbeddedCacheManagerFactory { protected static final Log logger = LogFactory.getLog(AbstractEmbeddedCacheManagerFactory.class); private Resource configurationFileLocation; private GlobalConfigurationBuilder gcb; private ConfigurationBuilder builder; // ------------------------------------------------------------------------ // Create fully configured EmbeddedCacheManager instance // ------------------------------------------------------------------------ protected EmbeddedCacheManager createBackingEmbeddedCacheManager() throws IOException { if (configurationFileLocation != null) { ConfigurationBuilderHolder configurationBuilderHolder = new ParserRegistry(Thread.currentThread().getContextClassLoader()) .parse(configurationFileLocation.getInputStream()); if(gcb != null) { configurationBuilderHolder.getGlobalConfigurationBuilder().read(gcb.build()); } if (builder != null) { configurationBuilderHolder.getDefaultConfigurationBuilder().read(builder.build()); } return new DefaultCacheManager(configurationBuilderHolder, true); } else { if (gcb == null) { if (logger.isDebugEnabled()) logger.debug("GlobalConfigurationBuilder is null. Using default new " + "instance."); gcb = new GlobalConfigurationBuilder(); gcb.globalJmxStatistics().allowDuplicateDomains(true); } if (builder == null) { if (logger.isDebugEnabled()) logger.debug("ConfigurationBuilder is null. Using default new instance."); builder = new ConfigurationBuilder(); } return new DefaultCacheManager(gcb.build(), builder.build()); } } // ------------------------------------------------------------------------ // Setter for location of configuration file // ------------------------------------------------------------------------ /** *

* Sets the {@link org.springframework.core.io.Resource location} of the * configuration file which will be used to configure the * {@link org.infinispan.manager.EmbeddedCacheManager EmbeddedCacheManager} the * {@link org.infinispan.spring.provider.SpringEmbeddedCacheManager * SpringEmbeddedCacheManager} created by this FactoryBean delegates * to. If no location is supplied, Infinispan's default configuration will be used. *

*

* Note that configuration settings defined via using explicit setters exposed by this * FactoryBean take precedence over those defined in the configuration file pointed * to by configurationFileLocation. *

* * @param configurationFileLocation * The {@link org.springframework.core.io.Resource location} of the * configuration file which will be used to configure the * {@link org.infinispan.manager.EmbeddedCacheManager * EmbeddedCacheManager} the * {@link org.infinispan.spring.provider.SpringEmbeddedCacheManager * SpringEmbeddedCacheManager} created by this FactoryBean * delegates to */ public void setConfigurationFileLocation(final Resource configurationFileLocation) { this.configurationFileLocation = configurationFileLocation; } /** * Sets the {@link GlobalConfigurationBuilder} to use when creating an EmbeddedCacheManager. * * @param gcb the GlobalConfigurationBuilder instance. */ public void addCustomGlobalConfiguration(final GlobalConfigurationBuilder gcb) { this.gcb = gcb; } /** * Sets the {@link ConfigurationBuilder} to use when creating an EmbeddedCacheManager. * * @param builder the ConfigurationBuilder instance. */ public void addCustomCacheConfiguration(final ConfigurationBuilder builder) { this.builder = builder; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy