Package org.springframework.data.gemfire
Class AbstractBasicCacheFactoryBean
java.lang.Object
org.springframework.data.gemfire.support.AbstractFactoryBeanSupport<GemFireCache>
org.springframework.data.gemfire.AbstractBasicCacheFactoryBean
- All Implemented Interfaces:
Aware,BeanClassLoaderAware,BeanFactoryAware,BeanNameAware,DisposableBean,FactoryBean<GemFireCache>,InitializingBean,Phased,PersistenceExceptionTranslator
- Direct Known Subclasses:
AbstractConfigurableCacheFactoryBean
public abstract class AbstractBasicCacheFactoryBean
extends AbstractFactoryBeanSupport<GemFireCache>
implements DisposableBean, InitializingBean, PersistenceExceptionTranslator, Phased
Abstract base class for
CacheFactoryBean and ClientCacheFactoryBean classes,
used to create Apache Geode peer Cache and ClientCache instances, respectively.
This class implements Spring's PersistenceExceptionTranslator interface and is auto-detected by Spring's
PersistenceExceptionTranslationPostProcessor to enable AOP-based translation of native Apache Geode
RuntimeExceptions to Spring's DataAccessException hierarchy. Therefore,
the presence of this class automatically enables Spring's PersistenceExceptionTranslationPostProcessor
to translate native Apache Geode thrown GemFireException and GemFireCheckedException types
as Spring DataAccessExceptions.
In addition, this class also assumes the responsibility of positioning the creation of the cache in the appropriate
phase of the Spring container's lifecycle, providing default callbacks for both initialization and destruction.
More importantly, this abstract class encapsulates configuration applicable to tuning Apache Geode in order to
efficiently use JVM Heap memory. Since Apache Geode stores data in-memory, on the JVM Heap, it is important that
Apache Geode be tuned to monitor the JVM Heap and respond to memory pressure accordingly, by evicting data
and issuing warnings when the JVM Heap reaches critical mass.
This abstract class is also concerned with the configuration of PDX and transaction event handling along with
whether the contents (entries) of the cache should be made effectively immutable on reads (i.e. get(key)).
In summary, this abstract class primarily handles and encapsulates the configuration of the following concerns:
- copy-on-read semantics
- JVM Heap memory management
- PDX serialization
- Transaction event processing
ClientCache and peer Cache instances.- Since:
- 2.5.0
- Author:
- John Blum
- See Also:
-
GemFireCheckedExceptionGemFireExceptionCacheCacheFactoryDiskStoreGemFireCacheRegionTransactionListenerTransactionWriterClientCacheClientCacheFactoryPdxSerializerDisposableBeanFactoryBeanInitializingBeanPhasedDataAccessExceptionPersistenceExceptionTranslationPostProcessorPersistenceExceptionTranslatorCacheFactoryBeanClientCacheFactoryBeanClientCacheConfigurerPeerCacheConfigurerAbstractFactoryBeanSupport
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface for initializing aCacheFactoryor aClientCacheFactoryinstance, which is used to create an instance ofGemFireCache.static interfaceCallback interface to configure PDX. -
Field Summary
Fields inherited from class org.springframework.data.gemfire.support.AbstractFactoryBeanSupport
DEFAULT_SINGLETONFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInitializes this cacheFactoryBeanafter all properties for this cache bean have been set by the Spring container.protected abstract voidApplies any user-defined cache configurers (e.g.protected voidclose(GemFireCache cache) Null-safe method used to close theGemFireCacheby callingRegionService.close()iff the cache is not already closed.protected GemFireCacheConfigures theGemFireCachecritical and eviction heap thresholds as percentages.protected GemFireCacheConfigures theGemFireCachecritical and eviction off-heap thresholds as percentages.protected <T> TconfigurePdx(AbstractBasicCacheFactoryBean.PdxConfigurer<T> pdxConfigurer) Configures the cache to use PDX serialization.voiddestroy()Destroys the cache bean on Spring container shutdown.protected abstract <T extends GemFireCache>
Tprotected abstract GemFireCacheprotected Class<? extends GemFireCache>By default, returnsGemFireCacheClass.protected <T extends GemFireCache>
TFetches an existing cache instance from the Apache Geode cache factory.<T extends GemFireCache>
TgetCache()Returns a reference to the constructed, configured an initializedGemFireCacheinstance created by this cacheFactoryBean.Return theAbstractBasicCacheFactoryBean.CacheFactoryInitializercalled by thisFactoryBeanto initialize the Apache Geode cache factory used to create the cache constructed by thisFactoryBean.Returns the configuration of theGemFireCache.getCopyOnRead()property set on theGemFireCache.Gets the configuration of theGemFireCachecritical heap percentage property.Gets the configuration of theGemFireCachecritical off-heap percentage property.Gets the configuration of theGemFireCacheeviction heap percentage property.Gets the configuration of theGemFireCacheeviction off-heap percentage property.Returns thecache object referencecreated by this cacheFactoryBean.Class<? extends GemFireCache><T extends GemFireCache>
Optional<T>Returns anOptionalreference to the constructed, configured and initializedGemFireCacheinstance created by this cacheFactoryBean.Gets the configuration determining whether PDX will ignore unread fields when deserializing PDX bytes back to anObject.Gets the configuration determining whetherobjectsstored in the Apache Geodecacheas PDX will be read back as PDX bytes or (deserialized) as anObjectwhenRegion.get(Object)is called.Get a reference to the configuredPdxSerializerused by this cache to de/serializeobjectsstored in the cache and distributed/transferred across the distributed system as PDX bytes.intgetPhase()Returns the configured lifecycle phase for this cache bean in the Spring container.Returns theListof configured, application-definedTransactionListenersregistered with the cache (transaction manager) to enable applications to receive transaction events after a transaction is processed (i.e. committed or rolled back).Return the configuredTransactionWriterused to process and handle transaction events.protected ObjectinitializeFactory(Object factory) Initializes the givenCacheFactoryorClientCacheFactorywith the configuredAbstractBasicCacheFactoryBean.CacheFactoryInitializer.booleanisClose()Returns a boolean value used to determine whether the cache will be closed on shutdown of the Spring container.booleanDetermines whetherobjectsstored in theGemFireCacheare copied when read (i.e.protected booleanisNotClosed(GemFireCache cache) Determines if theGemFireCachehas not been closed yet.protected GemFireCacheRegisters configured, application-definedTransactionListenerswith the cache (transaction manager) to listen for and receive transaction events when a (cache) transaction is processed (e.g. committed or rolled back).protected GemFireCacheRegisters the configured, application-definedTransactionWriterwith the cache (transaction manager) to receive transaction events with the intent to alter the transaction outcome (e.g. veto).protected voidsetCache(GemFireCache cache) Sets a reference to the constructed, configured an initializedGemFireCacheinstance created by this cacheFactoryBean.voidsetCacheFactoryInitializer(AbstractBasicCacheFactoryBean.CacheFactoryInitializer cacheFactoryInitializer) Set theAbstractBasicCacheFactoryBean.CacheFactoryInitializercalled by thisFactoryBeanto initialize the Apache Geode cache factory used to create the cache constructed by thisFactoryBean.voidsetClose(boolean close) Sets a boolean value used to determine whether the cache should be closed on shutdown of the Spring container.voidsetCopyOnRead(Boolean copyOnRead) Sets theGemFireCache.getCopyOnRead()property of theGemFireCache.voidsetCriticalHeapPercentage(Float criticalHeapPercentage) Set theGemFireCachecritical heap percentage property.voidsetCriticalOffHeapPercentage(Float criticalOffHeapPercentage) Set theGemFireCachecritical off-heap percentage property.voidsetEvictionHeapPercentage(Float evictionHeapPercentage) Set theGemFireCacheeviction heap percentage property.voidsetEvictionOffHeapPercentage(Float evictionOffHeapPercentage) Set theGemFireCacheeviction off-heap percentage property.voidsetPdxDiskStoreName(String pdxDiskStoreName) voidsetPdxIgnoreUnreadFields(Boolean pdxIgnoreUnreadFields) Configures whether PDX will ignore unread fields when deserializing PDX bytes back to anObject.voidsetPdxPersistent(Boolean pdxPersistent) voidsetPdxReadSerialized(Boolean pdxReadSerialized) Configures whetherobjectsstored in the Apache Geodecacheas PDX will be read back as PDX bytes or (deserialized) as anObjectwhenRegion.get(Object)is called.voidsetPdxSerializer(PdxSerializer serializer) Configures a reference toPdxSerializerused by this cache to de/serializeobjectsstored in the cache and distributed/transferred across the distributed system as PDX bytes.protected voidsetPhase(int phase) Set the lifecycle phase for this cache bean in the Spring container.voidsetTransactionListeners(List<TransactionListener> transactionListeners) Configures the cache (transaction manager) with aListofTransactionListenersimplemented by applications to listen for and receive transaction events after a transaction is processed (i.e. committed or rolled back).voidsetTransactionWriter(TransactionWriter transactionWriter) Configures aTransactionWriterimplemented by the application to receive transaction events and perform a action, like a veto.translateExceptionIfPossible(RuntimeException exception) Translates the thrown Apache GeodeRuntimeExceptioninto a correspondingExceptionfrom Spring's genericDataAccessExceptionhierarchy if possible.Methods inherited from class org.springframework.data.gemfire.support.AbstractFactoryBeanSupport
getBeanClassLoader, getBeanFactory, getBeanName, getLog, getOptionalLog, isDebugLoggingEnabled, isErrorLoggingEnabled, isInfoLoggingEnabled, isSingleton, isWarnLoggingEnabled, logDebug, logDebug, logError, logError, logInfo, logInfo, logWarning, logWarning, newLog, setBeanClassLoader, setBeanFactory, setBeanName
-
Constructor Details
-
AbstractBasicCacheFactoryBean
public AbstractBasicCacheFactoryBean()
-
-
Method Details
-
setCache
Sets a reference to the constructed, configured an initializedGemFireCacheinstance created by this cacheFactoryBean.- Parameters:
cache-GemFireCachecreated by this cacheFactoryBean.- See Also:
-
getCache
Returns a reference to the constructed, configured an initializedGemFireCacheinstance created by this cacheFactoryBean.- Type Parameters:
T- parameterizedClasstype extendingGemFireCache.- Returns:
- a reference to the
GemFireCachecreated by this cacheFactoryBean. - See Also:
-
getOptionalCache
Returns anOptionalreference to the constructed, configured and initializedGemFireCacheinstance created by this cacheFactoryBean.- Type Parameters:
T- parameterizedClasstype extendingGemFireCache.- Returns:
- an
Optionalreference to theGemFireCachecreated by this {cache @link FactoryBean}. - See Also:
-
setCacheFactoryInitializer
public void setCacheFactoryInitializer(@Nullable AbstractBasicCacheFactoryBean.CacheFactoryInitializer cacheFactoryInitializer) Set theAbstractBasicCacheFactoryBean.CacheFactoryInitializercalled by thisFactoryBeanto initialize the Apache Geode cache factory used to create the cache constructed by thisFactoryBean.- Parameters:
cacheFactoryInitializer-AbstractBasicCacheFactoryBean.CacheFactoryInitializercalled to initialize the cache factory.- See Also:
-
getCacheFactoryInitializer
Return theAbstractBasicCacheFactoryBean.CacheFactoryInitializercalled by thisFactoryBeanto initialize the Apache Geode cache factory used to create the cache constructed by thisFactoryBean.- Returns:
- the
AbstractBasicCacheFactoryBean.CacheFactoryInitializercalled to initialize the cache factory. - See Also:
-
setClose
public void setClose(boolean close) Sets a boolean value used to determine whether the cache should be closed on shutdown of the Spring container.- Parameters:
close- boolean value used to determine whether the cache will be closed on shutdown of the Spring container.
-
isClose
public boolean isClose()Returns a boolean value used to determine whether the cache will be closed on shutdown of the Spring container. Defaults to true.- Returns:
- a boolean value used to determine whether the cache will be closed on shutdown of the Spring container.
-
setCopyOnRead
Sets theGemFireCache.getCopyOnRead()property of theGemFireCache.- Parameters:
copyOnRead- aBooleanvalue to indicate whetherobjectsstored in theGemFireCacheare copied on read (i.e.Region.get(Object).
-
getCopyOnRead
Returns the configuration of theGemFireCache.getCopyOnRead()property set on theGemFireCache.- Returns:
- a
Booleanvalue to indicate whetherobjectsstored in theGemFireCacheare copied on read (i.e.Region.get(Object).
-
isCopyOnRead
public boolean isCopyOnRead()Determines whetherobjectsstored in theGemFireCacheare copied when read (i.e.Region.get(Object). Defaults to false.- Returns:
- a boolean value indicating whether
objectsstored in theGemFireCacheare copied when read (i.e.Region.get(Object). - See Also:
-
setCriticalHeapPercentage
Set theGemFireCachecritical heap percentage property.- Parameters:
criticalHeapPercentage-Floatvalue specifying the configuration for theGemFireCachecritical heap percentage.
-
getCriticalHeapPercentage
Gets the configuration of theGemFireCachecritical heap percentage property.- Returns:
- a
Floatvalue specifying the configuration for theGemFireCachecritical heap percentage.
-
setCriticalOffHeapPercentage
Set theGemFireCachecritical off-heap percentage property.- Parameters:
criticalOffHeapPercentage-Floatvalue specifying the configuration for theGemFireCachecritical off-heap percentage.
-
getCriticalOffHeapPercentage
Gets the configuration of theGemFireCachecritical off-heap percentage property.- Returns:
- a
Floatvalue specifying the configuration for theGemFireCachecritical off-heap percentage.
-
setEvictionHeapPercentage
Set theGemFireCacheeviction heap percentage property.- Parameters:
evictionHeapPercentage-Floatvalue specifying the configuration for theGemFireCacheeviction heap percentage.
-
getEvictionHeapPercentage
Gets the configuration of theGemFireCacheeviction heap percentage property.- Returns:
- a
Floatvalue specifying the configuration for theGemFireCacheeviction heap percentage.
-
setEvictionOffHeapPercentage
Set theGemFireCacheeviction off-heap percentage property.- Parameters:
evictionOffHeapPercentage-Floatvalue specifying the configuration for theGemFireCacheeviction off-heap percentage.
-
getEvictionOffHeapPercentage
Gets the configuration of theGemFireCacheeviction off-heap percentage property.- Returns:
- a
Floatvalue specifying the configuration for theGemFireCacheeviction off-heap percentage.
-
getObject
Returns thecache object referencecreated by this cacheFactoryBean.- Specified by:
getObjectin interfaceFactoryBean<GemFireCache>- Returns:
- the
cache object referencecreated by this cacheFactoryBean. - Throws:
Exception- See Also:
-
doGetObject
- Returns:
- a new constructed, configured and initialized
GemFireCacheinstance. - See Also:
-
getObjectType
- Specified by:
getObjectTypein interfaceFactoryBean<GemFireCache>- Returns:
- the
typeofGemFireCachecreated by this cacheFactoryBean. - See Also:
-
doGetObjectType
By default, returnsGemFireCacheClass.- Returns:
GemFireCacheClassby default.- See Also:
-
setPdxDiskStoreName
-
getPdxDiskStoreName
-
setPdxIgnoreUnreadFields
Configures whether PDX will ignore unread fields when deserializing PDX bytes back to anObject. Defaults to false.- Parameters:
pdxIgnoreUnreadFields-Booleanvalue controlling ignoring unread fields.- See Also:
-
getPdxIgnoreUnreadFields
Gets the configuration determining whether PDX will ignore unread fields when deserializing PDX bytes back to anObject. Defaults to false.- Returns:
- a
Booleanvalue controlling ignoring unread fields. - See Also:
-
setPdxPersistent
-
getPdxPersistent
Gets the configuration determining whethertypemetadata forobjectsserialized to PDX will be persisted to disk. -
setPdxReadSerialized
Configures whetherobjectsstored in the Apache Geodecacheas PDX will be read back as PDX bytes or (deserialized) as anObjectwhenRegion.get(Object)is called.- Parameters:
pdxReadSerialized-Booleanvalue controlling the PDX read serialized function.- See Also:
-
getPdxReadSerialized
Gets the configuration determining whetherobjectsstored in the Apache Geodecacheas PDX will be read back as PDX bytes or (deserialized) as anObjectwhenRegion.get(Object)is called.- Returns:
- a
Booleanvalue controlling the PDX read serialized function. - See Also:
-
setPdxSerializer
Configures a reference toPdxSerializerused by this cache to de/serializeobjectsstored in the cache and distributed/transferred across the distributed system as PDX bytes.- Parameters:
serializer-PdxSerializerused by this cache to de/serializeobjectsas PDX.- See Also:
-
getPdxSerializer
Get a reference to the configuredPdxSerializerused by this cache to de/serializeobjectsstored in the cache and distributed/transferred across the distributed system as PDX bytes.- Returns:
- a reference to the configured
PdxSerializer. - See Also:
-
setPhase
protected void setPhase(int phase) Set the lifecycle phase for this cache bean in the Spring container.- Parameters:
phase-Integer.TYPEvalue specifying the lifecycle phase for this cache bean in the Spring container.- See Also:
-
getPhase
public int getPhase()Returns the configured lifecycle phase for this cache bean in the Spring container.- Specified by:
getPhasein interfacePhased- Returns:
- an
Integer.TYPEused specifying the lifecycle phase for this cache bean in the Spring container. - See Also:
-
setTransactionListeners
Configures the cache (transaction manager) with aListofTransactionListenersimplemented by applications to listen for and receive transaction events after a transaction is processed (i.e. committed or rolled back).- Parameters:
transactionListeners-Listof application-definedTransactionListenersregistered with the cache to listen for and receive transaction events.- See Also:
-
getTransactionListeners
Returns theListof configured, application-definedTransactionListenersregistered with the cache (transaction manager) to enable applications to receive transaction events after a transaction is processed (i.e. committed or rolled back).- Returns:
- a
Listof application-definedTransactionListenersregistered with the cache (transaction manager) to listen for and receive transaction events. - See Also:
-
setTransactionWriter
Configures aTransactionWriterimplemented by the application to receive transaction events and perform a action, like a veto.- Parameters:
transactionWriter-TransactionWriterreceiving transaction events.- See Also:
-
getTransactionWriter
Return the configuredTransactionWriterused to process and handle transaction events.- Returns:
- the configured
TransactionWriter. - See Also:
-
afterPropertiesSet
Initializes this cacheFactoryBeanafter all properties for this cache bean have been set by the Spring container.- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception- if initialization fails.- See Also:
-
applyCacheConfigurers
protected abstract void applyCacheConfigurers()Applies any user-defined cache configurers (e.g.ClientCacheConfigurerorPeerCacheConfigurer) to this cacheFactoryBeanbefore cache construction, configuration and initialization. -
close
Null-safe method used to close theGemFireCacheby callingRegionService.close()iff the cache is not already closed.- Parameters:
cache-GemFireCacheto close.- See Also:
-
isNotClosed
Determines if theGemFireCachehas not been closed yet.- Parameters:
cache-GemFireCacheto evaluate.- Returns:
- a boolean value indicating if the
GemFireCacheis not yet closed. - See Also:
-
destroy
public void destroy()Destroys the cache bean on Spring container shutdown.- Specified by:
destroyin interfaceDisposableBean- See Also:
-
configureHeapPercentages
Configures theGemFireCachecritical and eviction heap thresholds as percentages.- Parameters:
cache-GemFireCacheto configure the critical and eviction heap thresholds; must not be null.- Returns:
- the given
GemFireCache. - Throws:
IllegalArgumentException- if the critical or eviction heap thresholds are not valid percentages.- See Also:
-
configureOffHeapPercentages
Configures theGemFireCachecritical and eviction off-heap thresholds as percentages.- Parameters:
cache-GemFireCacheto configure the critical and eviction off-heap thresholds; must not be null.- Returns:
- the given
GemFireCache. - Throws:
IllegalArgumentException- if the critical or eviction off-heap thresholds are not valid percentages.- See Also:
-
configurePdx
Configures the cache to use PDX serialization.- Parameters:
pdxConfigurer-AbstractBasicCacheFactoryBean.PdxConfigurerused to configure the cache with PDX serialization.- Returns:
- the
AbstractBasicCacheFactoryBean.PdxConfigurer.getTarget().
-
fetchCache
Fetches an existing cache instance from the Apache Geode cache factory.- Type Parameters:
T- parameterizedClasstype extendingGemFireCache.- Returns:
- an existing cache instance if available.
- Throws:
CacheClosedException- if an existing cache instance does not exist.- See Also:
-
doFetchCache
Called byfetchCache()if theGemFireCachereference returned bygetCache()is null. This method is typically implemented by callingCacheFactory.getAnyInstance()orClientCacheFactory.getAnyInstance()depending on theGemFireCachetype declared and used in the Spring application.- Type Parameters:
T- parameterizedClasstype extendingGemFireCache.- Returns:
- a (existing) reference to a
GemFireCacheinstance. - Throws:
CacheClosedException- if aGemFireCachereference does not exist.- See Also:
-
initializeFactory
Initializes the givenCacheFactoryorClientCacheFactorywith the configuredAbstractBasicCacheFactoryBean.CacheFactoryInitializer.- Parameters:
factory-CacheFactoryorClientCacheFactoryto initialize.- Returns:
- the initialized
CacheFactoryorClientCacheFactory. - See Also:
-
registerTransactionListeners
Registers configured, application-definedTransactionListenerswith the cache (transaction manager) to listen for and receive transaction events when a (cache) transaction is processed (e.g. committed or rolled back).- Parameters:
cache-GemFireCacheused to register the configured, application-definedTransactionListeners; must not be null.- Returns:
- the given
GemFireCache. - See Also:
-
registerTransactionWriter
Registers the configured, application-definedTransactionWriterwith the cache (transaction manager) to receive transaction events with the intent to alter the transaction outcome (e.g. veto).- Parameters:
cache-GemFireCacheused to register the configured, application-definedTransactionWriter, must not be null.- Returns:
- the given
GemFireCache. - See Also:
-
translateExceptionIfPossible
@Nullable public DataAccessException translateExceptionIfPossible(@Nullable RuntimeException exception) Translates the thrown Apache GeodeRuntimeExceptioninto a correspondingExceptionfrom Spring's genericDataAccessExceptionhierarchy if possible.- Specified by:
translateExceptionIfPossiblein interfacePersistenceExceptionTranslator- Parameters:
exception- the Apache GeodeRuntimeExceptionto translate.- Returns:
- the translated Spring
DataAccessExceptionor null if the Apache GeodeRuntimeExceptioncould not be translated. - See Also:
-