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

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

There is a newer version: 14.0.33.Final
Show newest version
package org.infinispan.spring.embedded;

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.getURL()); 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) { ConfigurationBuilderHolder configurationBuilderHolder = new ConfigurationBuilderHolder(Thread.currentThread().getContextClassLoader(), gcb); configurationBuilderHolder.getGlobalConfigurationBuilder().read(gcb.build()); if (gcb.defaultCacheName().isPresent()) { configurationBuilderHolder.getNamedConfigurationBuilders().put(gcb.defaultCacheName().get(), builder); } else { throw logger.noDefaultCache(); } return new DefaultCacheManager(configurationBuilderHolder, true); } else { return new DefaultCacheManager(gcb.build()); } } } // ------------------------------------------------------------------------ // Setter for location of configuration file // ------------------------------------------------------------------------ /** *

* Sets the {@link Resource location} of the * configuration file which will be used to configure the * {@link EmbeddedCacheManager EmbeddedCacheManager} the * {@link org.infinispan.spring.embedded.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 Resource location} of the * configuration file which will be used to configure the * {@link EmbeddedCacheManager * EmbeddedCacheManager} the * {@link org.infinispan.spring.embedded.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