org.springframework.data.gemfire
Class CacheFactoryBean

java.lang.Object
  extended by org.springframework.data.gemfire.CacheFactoryBean
All Implemented Interfaces:
Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, FactoryBean<com.gemstone.gemfire.cache.Cache>, PersistenceExceptionTranslator
Direct Known Subclasses:
ClientCacheFactoryBean

public class CacheFactoryBean
extends Object
implements BeanNameAware, BeanFactoryAware, BeanClassLoaderAware, DisposableBean, FactoryBean<com.gemstone.gemfire.cache.Cache>, PersistenceExceptionTranslator

Factory used for configuring a Gemfire Cache manager. Allows either retrieval of an existing, opened cache or the creation of a new one.

This class implements the PersistenceExceptionTranslator interface, as auto-detected by Spring's PersistenceExceptionTranslationPostProcessor , for AOP-based translation of native exceptions to Spring DataAccessExceptions. Hence, the presence of this class automatically enables a PersistenceExceptionTranslationPostProcessor to translate GemFire exceptions.


Nested Class Summary
static class CacheFactoryBean.DynamicRegionSupport
           
static class CacheFactoryBean.JndiDataSource
           
 
Field Summary
protected  ClassLoader beanClassLoader
           
protected  BeanFactory beanFactory
           
protected  String beanName
           
protected  com.gemstone.gemfire.cache.Cache cache
           
protected  Resource cacheXml
           
protected  boolean close
           
protected  Boolean copyOnRead
           
protected  Float criticalHeapPercentage
           
protected  CacheFactoryBean.DynamicRegionSupport dynamicRegionSupport
           
protected  Float evictionHeapPercentage
           
protected  GemfireBeanFactoryLocator factoryLocator
           
protected  Object gatewayConflictResolver
           
protected  List<CacheFactoryBean.JndiDataSource> jndiDataSources
           
protected  Integer lockLease
           
protected  Integer lockTimeout
           
protected  org.apache.commons.logging.Log log
           
protected  Integer messageSyncInterval
           
protected  String pdxDiskStoreName
           
protected  Boolean pdxIgnoreUnreadFields
           
protected  Boolean pdxPersistent
           
protected  Boolean pdxReadSerialized
           
protected  Object pdxSerializer
           
protected  Properties properties
           
protected  Integer searchTimeout
           
protected  List<com.gemstone.gemfire.cache.TransactionListener> transactionListeners
           
protected  com.gemstone.gemfire.cache.TransactionWriter transactionWriter
           
protected  boolean useBeanFactoryLocator
           
 
Constructor Summary
CacheFactoryBean()
           
 
Method Summary
protected  void applyPdxOptions(Object factory)
          Sets the PDX properties for the given object.
protected  com.gemstone.gemfire.cache.GemFireCache createCache(Object factory)
           
protected  Object createFactory(Properties props)
           
 void destroy()
           
protected  com.gemstone.gemfire.cache.GemFireCache fetchCache()
           
 ClassLoader getBeanClassLoader()
           
 BeanFactory getBeanFactory()
           
 GemfireBeanFactoryLocator getBeanFactoryLocator()
           
 String getBeanName()
           
 Resource getCacheXml()
           
 Boolean getCopyOnRead()
           
 Float getCriticalHeapPercentage()
           
 CacheFactoryBean.DynamicRegionSupport getDynamicRegionSupport()
           
 Float getEvictionHeapPercentage()
           
 Object getGatewayConflictResolver()
           
 List<CacheFactoryBean.JndiDataSource> getJndiDataSources()
           
 Integer getLockLease()
           
 Integer getLockTimeout()
           
 Integer getMessageSyncInterval()
           
 com.gemstone.gemfire.cache.Cache getObject()
           
 Class<? extends com.gemstone.gemfire.cache.Cache> getObjectType()
           
 String getPdxDiskStoreName()
           
 Boolean getPdxIgnoreUnreadFields()
           
 Boolean getPdxPersistent()
           
 Boolean getPdxReadSerialized()
           
 Object getPdxSerializer()
           
 Properties getProperties()
           
 Integer getSearchTimeout()
           
 List<com.gemstone.gemfire.cache.TransactionListener> getTransactionListeners()
           
 com.gemstone.gemfire.cache.TransactionWriter getTransactionWriter()
           
 boolean isSingleton()
           
protected  void registerTransactionListeners()
          Register all declared transaction listeners
protected  void registerTransactionWriter()
          Register a transaction writer if declared
 void setBeanClassLoader(ClassLoader classLoader)
           
 void setBeanFactory(BeanFactory beanFactory)
           
 void setBeanName(String name)
           
 void setCacheXml(Resource cacheXml)
          Sets the cache configuration.
 void setClose(boolean close)
           
 void setCopyOnRead(Boolean copyOnRead)
           
 void setCriticalHeapPercentage(Float criticalHeapPercentage)
           
 void setDynamicRegionSupport(CacheFactoryBean.DynamicRegionSupport dynamicRegionSupport)
           
 void setEvictionHeapPercentage(Float evictionHeapPercentage)
           
 void setGatewayConflictResolver(Object gatewayConflictResolver)
          Requires GemFire 7.0 or higher
 void setJndiDataSources(List<CacheFactoryBean.JndiDataSource> jndiDataSources)
           
 void setLockLease(Integer lockLease)
           
 void setLockTimeout(Integer lockTimeout)
           
 void setMessageSyncInterval(Integer messageSyncInterval)
           
 void setPdxDiskStoreName(String pdxDiskStoreName)
          Set the disk store that is used for PDX meta data.
 void setPdxIgnoreUnreadFields(Boolean pdxIgnoreUnreadFields)
          Controls whether pdx ignores fields that were unread during deserialization.
 void setPdxPersistent(Boolean pdxPersistent)
          Sets the object preference to PdxInstance type.
 void setPdxReadSerialized(Boolean pdxReadSerialized)
          Controls whether the type metadata for PDX objects is persisted to disk.
 void setPdxSerializer(Object serializer)
          Sets the PdxSerializable for this cache.
 void setProperties(Properties properties)
          Sets the cache properties.
 void setSearchTimeout(Integer searchTimeout)
           
 void setTransactionListeners(List<com.gemstone.gemfire.cache.TransactionListener> transactionListeners)
           
 void setTransactionWriter(com.gemstone.gemfire.cache.TransactionWriter transactionWriter)
           
 void setUseBeanFactoryLocator(boolean usage)
          Indicates whether a bean factory locator is enabled (default) for this cache definition or not.
 DataAccessException translateExceptionIfPossible(RuntimeException ex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log

cache

protected com.gemstone.gemfire.cache.Cache cache

cacheXml

protected Resource cacheXml

properties

protected Properties properties

beanClassLoader

protected ClassLoader beanClassLoader

factoryLocator

protected GemfireBeanFactoryLocator factoryLocator

beanFactory

protected BeanFactory beanFactory

beanName

protected String beanName

useBeanFactoryLocator

protected boolean useBeanFactoryLocator

close

protected boolean close

pdxSerializer

protected Object pdxSerializer

pdxPersistent

protected Boolean pdxPersistent

pdxReadSerialized

protected Boolean pdxReadSerialized

pdxIgnoreUnreadFields

protected Boolean pdxIgnoreUnreadFields

pdxDiskStoreName

protected String pdxDiskStoreName

copyOnRead

protected Boolean copyOnRead

lockTimeout

protected Integer lockTimeout

lockLease

protected Integer lockLease

messageSyncInterval

protected Integer messageSyncInterval

searchTimeout

protected Integer searchTimeout

transactionListeners

protected List<com.gemstone.gemfire.cache.TransactionListener> transactionListeners

transactionWriter

protected com.gemstone.gemfire.cache.TransactionWriter transactionWriter

evictionHeapPercentage

protected Float evictionHeapPercentage

criticalHeapPercentage

protected Float criticalHeapPercentage

dynamicRegionSupport

protected CacheFactoryBean.DynamicRegionSupport dynamicRegionSupport

jndiDataSources

protected List<CacheFactoryBean.JndiDataSource> jndiDataSources

gatewayConflictResolver

protected Object gatewayConflictResolver
Constructor Detail

CacheFactoryBean

public CacheFactoryBean()
Method Detail

registerTransactionWriter

protected void registerTransactionWriter()
Register a transaction writer if declared


registerTransactionListeners

protected void registerTransactionListeners()
Register all declared transaction listeners


applyPdxOptions

protected void applyPdxOptions(Object factory)
Sets the PDX properties for the given object. Note this is implementation specific as it depends on the type of the factory passed in.

Parameters:
factory -

createFactory

protected Object createFactory(Properties props)

fetchCache

protected com.gemstone.gemfire.cache.GemFireCache fetchCache()

createCache

protected com.gemstone.gemfire.cache.GemFireCache createCache(Object factory)

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface DisposableBean
Throws:
Exception

translateExceptionIfPossible

public DataAccessException translateExceptionIfPossible(RuntimeException ex)
Specified by:
translateExceptionIfPossible in interface PersistenceExceptionTranslator

getObject

public com.gemstone.gemfire.cache.Cache getObject()
                                           throws Exception
Specified by:
getObject in interface FactoryBean<com.gemstone.gemfire.cache.Cache>
Throws:
Exception

getObjectType

public Class<? extends com.gemstone.gemfire.cache.Cache> getObjectType()
Specified by:
getObjectType in interface FactoryBean<com.gemstone.gemfire.cache.Cache>

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface FactoryBean<com.gemstone.gemfire.cache.Cache>

setBeanClassLoader

public void setBeanClassLoader(ClassLoader classLoader)
Specified by:
setBeanClassLoader in interface BeanClassLoaderAware

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
                    throws BeansException
Specified by:
setBeanFactory in interface BeanFactoryAware
Throws:
BeansException

setBeanName

public void setBeanName(String name)
Specified by:
setBeanName in interface BeanNameAware

setProperties

public void setProperties(Properties properties)
Sets the cache properties.

Parameters:
properties - the properties to set

setCacheXml

public void setCacheXml(Resource cacheXml)
Sets the cache configuration.

Parameters:
cacheXml - the cacheXml to set

setUseBeanFactoryLocator

public void setUseBeanFactoryLocator(boolean usage)
Indicates whether a bean factory locator is enabled (default) for this cache definition or not. The locator stores the enclosing bean factory reference to allow auto-wiring of Spring beans into GemFire managed classes. Usually disabled when the same cache is used in multiple application context/bean factories inside the same VM.

Parameters:
usage - true if the bean factory locator is used underneath or not

setPdxSerializer

public void setPdxSerializer(Object serializer)
Sets the PdxSerializable for this cache. Applicable on GemFire 6.6 or higher. The argument is of type object for compatibility with GemFire 6.5.

Parameters:
serializer - pdx serializer configured for this cache.

setPdxPersistent

public void setPdxPersistent(Boolean pdxPersistent)
Sets the object preference to PdxInstance type. Applicable on GemFire 6.6 or higher.

Parameters:
pdxPersistent - the pdxPersistent to set

setPdxReadSerialized

public void setPdxReadSerialized(Boolean pdxReadSerialized)
Controls whether the type metadata for PDX objects is persisted to disk. Applicable on GemFire 6.6 or higher.

Parameters:
pdxReadSerialized - the pdxReadSerialized to set

setPdxIgnoreUnreadFields

public void setPdxIgnoreUnreadFields(Boolean pdxIgnoreUnreadFields)
Controls whether pdx ignores fields that were unread during deserialization. Applicable on GemFire 6.6 or higher.

Parameters:
pdxIgnoreUnreadFields - the pdxIgnoreUnreadFields to set

setPdxDiskStoreName

public void setPdxDiskStoreName(String pdxDiskStoreName)
Set the disk store that is used for PDX meta data. Applicable on GemFire 6.6 or higher.

Parameters:
pdxDiskStoreName - the pdxDiskStoreName to set

getBeanFactory

public BeanFactory getBeanFactory()
Returns:
the beanFactory

setCopyOnRead

public void setCopyOnRead(Boolean copyOnRead)
Parameters:
copyOnRead -

setLockTimeout

public void setLockTimeout(Integer lockTimeout)
Parameters:
lockTimeout -

setLockLease

public void setLockLease(Integer lockLease)
Parameters:
lockLease -

setMessageSyncInterval

public void setMessageSyncInterval(Integer messageSyncInterval)
Parameters:
messageSyncInterval -

setSearchTimeout

public void setSearchTimeout(Integer searchTimeout)
Parameters:
searchTimeout -

setEvictionHeapPercentage

public void setEvictionHeapPercentage(Float evictionHeapPercentage)
Parameters:
evictionHeapPercentage -

setCriticalHeapPercentage

public void setCriticalHeapPercentage(Float criticalHeapPercentage)
Parameters:
criticalHeapPercentage -

setClose

public void setClose(boolean close)
Parameters:
close - set to false if destroy() should not close the cache

setTransactionListeners

public void setTransactionListeners(List<com.gemstone.gemfire.cache.TransactionListener> transactionListeners)
Parameters:
transactionListeners -

setTransactionWriter

public void setTransactionWriter(com.gemstone.gemfire.cache.TransactionWriter transactionWriter)
Parameters:
transactionWriter -

setGatewayConflictResolver

public void setGatewayConflictResolver(Object gatewayConflictResolver)
Requires GemFire 7.0 or higher

Parameters:
gatewayConflictResolver - defined as Object in the signature for backward compatibility with Gemfire 6 compatibility. This must be an instance of GatewayConflictResolver

setDynamicRegionSupport

public void setDynamicRegionSupport(CacheFactoryBean.DynamicRegionSupport dynamicRegionSupport)
Parameters:
dynamicRegionSupport -

setJndiDataSources

public void setJndiDataSources(List<CacheFactoryBean.JndiDataSource> jndiDataSources)
Parameters:
jndiDataSources -

getCacheXml

public Resource getCacheXml()
Returns:
the cacheXml

getProperties

public Properties getProperties()
Returns:
the properties

getBeanClassLoader

public ClassLoader getBeanClassLoader()
Returns:
the beanClassLoader

getBeanName

public String getBeanName()
Returns:
the beanName

getPdxSerializer

public Object getPdxSerializer()
Returns:
the pdxSerializer

getPdxPersistent

public Boolean getPdxPersistent()
Returns:
the pdxPersistent

getPdxReadSerialized

public Boolean getPdxReadSerialized()
Returns:
the pdxReadSerialized

getPdxIgnoreUnreadFields

public Boolean getPdxIgnoreUnreadFields()
Returns:
the pdxIgnoreUnreadFields

getPdxDiskStoreName

public String getPdxDiskStoreName()
Returns:
the pdxDiskStoreName

getCopyOnRead

public Boolean getCopyOnRead()
Returns:
the copyOnRead

getLockTimeout

public Integer getLockTimeout()
Returns:
the lockTimeout

getLockLease

public Integer getLockLease()
Returns:
the lockLease

getMessageSyncInterval

public Integer getMessageSyncInterval()
Returns:
the messageSyncInterval

getSearchTimeout

public Integer getSearchTimeout()
Returns:
the searchTimeout

getTransactionListeners

public List<com.gemstone.gemfire.cache.TransactionListener> getTransactionListeners()
Returns:
the transactionListeners

getTransactionWriter

public com.gemstone.gemfire.cache.TransactionWriter getTransactionWriter()
Returns:
the transactionWriter

getEvictionHeapPercentage

public Float getEvictionHeapPercentage()
Returns:
the evictionHeapPercentage

getCriticalHeapPercentage

public Float getCriticalHeapPercentage()
Returns:
the criticalHeapPercentage

getDynamicRegionSupport

public CacheFactoryBean.DynamicRegionSupport getDynamicRegionSupport()
Returns:
the dynamicRegionSupport

getJndiDataSources

public List<CacheFactoryBean.JndiDataSource> getJndiDataSources()
Returns:
the jndiDataSources

getGatewayConflictResolver

public Object getGatewayConflictResolver()
Returns:
the gatewayConflictResolver

getBeanFactoryLocator

public GemfireBeanFactoryLocator getBeanFactoryLocator()