org.infinispan.spring.config.InfinispanRemoteCacheManagerBeanDefinitionParser 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.
package org.infinispan.spring.config;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
* @author Marius Bogoevici
*/
public class InfinispanRemoteCacheManagerBeanDefinitionParser extends AbstractBeanDefinitionParser {
private static final String DEFAULT_CACHE_MANAGER_BEAN_NAME = "cacheManager";
private static final String CACHE_MANAGER_CLASS = "org.infinispan.spring.provider.SpringRemoteCacheManagerFactoryBean";
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(CACHE_MANAGER_CLASS);
String configFileLocation = element.getAttribute("configuration");
if (StringUtils.hasText(configFileLocation)) {
beanDefinitionBuilder.addPropertyValue("configurationPropertiesFileLocation", configFileLocation);
}
return beanDefinitionBuilder.getBeanDefinition();
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException {
String id = element.getAttribute("id");
if (!StringUtils.hasText(id)) {
id = DEFAULT_CACHE_MANAGER_BEAN_NAME;
}
return id;
}
}