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

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

package org.infinispan.spring;

import java.io.IOException;

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;

/**
 * 

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

* * @author Olaf Bergner * @author Marius Bogoevici */ public class AbstractEmbeddedCacheManagerFactory { private 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) { ConfigurationBuilder dcb = configurationBuilderHolder.getDefaultConfigurationBuilder(); if (dcb != null) dcb.read(builder.build()); else throw logger.noDefaultCache(); } return new DefaultCacheManager(configurationBuilderHolder, true); } else { if (gcb == null) { if (logger.isDebugEnabled()) logger.debug("GlobalConfigurationBuilder is null. Using default new " + "instance."); gcb = new GlobalConfigurationBuilder(); } 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