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:
-
GemFireCheckedException
GemFireException
Cache
CacheFactory
DiskStore
GemFireCache
Region
TransactionListener
TransactionWriter
ClientCache
ClientCacheFactory
PdxSerializer
DisposableBean
FactoryBean
InitializingBean
Phased
DataAccessException
PersistenceExceptionTranslationPostProcessor
PersistenceExceptionTranslator
CacheFactoryBean
ClientCacheFactoryBean
ClientCacheConfigurer
PeerCacheConfigurer
AbstractFactoryBeanSupport
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback interface for initializing aCacheFactory
or aClientCacheFactory
instance, which is used to create an instance ofGemFireCache
.static interface
Callback interface to configure PDX. -
Field Summary
Fields inherited from class org.springframework.data.gemfire.support.AbstractFactoryBeanSupport
DEFAULT_SINGLETON
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Initializes this cacheFactoryBean
after all properties for this cache bean have been set by the Spring container.protected abstract void
Applies any user-defined cache configurers (e.g.protected void
close
(GemFireCache cache) Null-safe method used to close theGemFireCache
by callingRegionService.close()
iff the cache is not already closed.protected GemFireCache
Configures theGemFireCache
critical and eviction heap thresholds as percentages.protected GemFireCache
Configures theGemFireCache
critical and eviction off-heap thresholds as percentages.protected <T> T
configurePdx
(AbstractBasicCacheFactoryBean.PdxConfigurer<T> pdxConfigurer) Configures the cache to use PDX serialization.void
destroy()
Destroys the cache bean on Spring container shutdown.protected abstract <T extends GemFireCache>
Tprotected abstract GemFireCache
protected Class<? extends GemFireCache>
By default, returnsGemFireCache
Class
.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 initializedGemFireCache
instance created by this cacheFactoryBean
.Return theAbstractBasicCacheFactoryBean.CacheFactoryInitializer
called by thisFactoryBean
to 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 theGemFireCache
critical heap percentage property.Gets the configuration of theGemFireCache
critical off-heap percentage property.Gets the configuration of theGemFireCache
eviction heap percentage property.Gets the configuration of theGemFireCache
eviction off-heap percentage property.Returns thecache object reference
created by this cacheFactoryBean
.Class<? extends GemFireCache>
<T extends GemFireCache>
Optional<T>Returns anOptional
reference to the constructed, configured and initializedGemFireCache
instance 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 whetherobjects
stored in the Apache Geodecache
as PDX will be read back as PDX bytes or (deserialized) as anObject
whenRegion.get(Object)
is called.Get a reference to the configuredPdxSerializer
used by this cache to de/serializeobjects
stored in the cache and distributed/transferred across the distributed system as PDX bytes.int
getPhase()
Returns the configured lifecycle phase for this cache bean in the Spring container.Returns theList
of configured, application-definedTransactionListeners
registered 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 configuredTransactionWriter
used to process and handle transaction events.protected Object
initializeFactory
(Object factory) Initializes the givenCacheFactory
orClientCacheFactory
with the configuredAbstractBasicCacheFactoryBean.CacheFactoryInitializer
.boolean
isClose()
Returns a boolean value used to determine whether the cache will be closed on shutdown of the Spring container.boolean
Determines whetherobjects
stored in theGemFireCache
are copied when read (i.e.protected boolean
isNotClosed
(GemFireCache cache) Determines if theGemFireCache
has not been closed yet.protected GemFireCache
Registers configured, application-definedTransactionListeners
with the cache (transaction manager) to listen for and receive transaction events when a (cache) transaction is processed (e.g. committed or rolled back).protected GemFireCache
Registers the configured, application-definedTransactionWriter
with the cache (transaction manager) to receive transaction events with the intent to alter the transaction outcome (e.g. veto).protected void
setCache
(GemFireCache cache) Sets a reference to the constructed, configured an initializedGemFireCache
instance created by this cacheFactoryBean
.void
setCacheFactoryInitializer
(AbstractBasicCacheFactoryBean.CacheFactoryInitializer cacheFactoryInitializer) Set theAbstractBasicCacheFactoryBean.CacheFactoryInitializer
called by thisFactoryBean
to initialize the Apache Geode cache factory used to create the cache constructed by thisFactoryBean
.void
setClose
(boolean close) Sets a boolean value used to determine whether the cache should be closed on shutdown of the Spring container.void
setCopyOnRead
(Boolean copyOnRead) Sets theGemFireCache.getCopyOnRead()
property of theGemFireCache
.void
setCriticalHeapPercentage
(Float criticalHeapPercentage) Set theGemFireCache
critical heap percentage property.void
setCriticalOffHeapPercentage
(Float criticalOffHeapPercentage) Set theGemFireCache
critical off-heap percentage property.void
setEvictionHeapPercentage
(Float evictionHeapPercentage) Set theGemFireCache
eviction heap percentage property.void
setEvictionOffHeapPercentage
(Float evictionOffHeapPercentage) Set theGemFireCache
eviction off-heap percentage property.void
setPdxDiskStoreName
(String pdxDiskStoreName) void
setPdxIgnoreUnreadFields
(Boolean pdxIgnoreUnreadFields) Configures whether PDX will ignore unread fields when deserializing PDX bytes back to anObject
.void
setPdxPersistent
(Boolean pdxPersistent) void
setPdxReadSerialized
(Boolean pdxReadSerialized) Configures whetherobjects
stored in the Apache Geodecache
as PDX will be read back as PDX bytes or (deserialized) as anObject
whenRegion.get(Object)
is called.void
setPdxSerializer
(PdxSerializer serializer) Configures a reference toPdxSerializer
used by this cache to de/serializeobjects
stored in the cache and distributed/transferred across the distributed system as PDX bytes.protected void
setPhase
(int phase) Set the lifecycle phase for this cache bean in the Spring container.void
setTransactionListeners
(List<TransactionListener> transactionListeners) Configures the cache (transaction manager) with aList
ofTransactionListeners
implemented by applications to listen for and receive transaction events after a transaction is processed (i.e. committed or rolled back).void
setTransactionWriter
(TransactionWriter transactionWriter) Configures aTransactionWriter
implemented by the application to receive transaction events and perform a action, like a veto.translateExceptionIfPossible
(RuntimeException exception) Translates the thrown Apache GeodeRuntimeException
into a correspondingException
from Spring's genericDataAccessException
hierarchy 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 initializedGemFireCache
instance created by this cacheFactoryBean
.- Parameters:
cache
-GemFireCache
created by this cacheFactoryBean
.- See Also:
-
getCache
Returns a reference to the constructed, configured an initializedGemFireCache
instance created by this cacheFactoryBean
.- Type Parameters:
T
- parameterizedClass
type extendingGemFireCache
.- Returns:
- a reference to the
GemFireCache
created by this cacheFactoryBean
. - See Also:
-
getOptionalCache
Returns anOptional
reference to the constructed, configured and initializedGemFireCache
instance created by this cacheFactoryBean
.- Type Parameters:
T
- parameterizedClass
type extendingGemFireCache
.- Returns:
- an
Optional
reference to theGemFireCache
created by this {cache @link FactoryBean}. - See Also:
-
setCacheFactoryInitializer
public void setCacheFactoryInitializer(@Nullable AbstractBasicCacheFactoryBean.CacheFactoryInitializer cacheFactoryInitializer) Set theAbstractBasicCacheFactoryBean.CacheFactoryInitializer
called by thisFactoryBean
to initialize the Apache Geode cache factory used to create the cache constructed by thisFactoryBean
.- Parameters:
cacheFactoryInitializer
-AbstractBasicCacheFactoryBean.CacheFactoryInitializer
called to initialize the cache factory.- See Also:
-
getCacheFactoryInitializer
Return theAbstractBasicCacheFactoryBean.CacheFactoryInitializer
called by thisFactoryBean
to initialize the Apache Geode cache factory used to create the cache constructed by thisFactoryBean
.- Returns:
- the
AbstractBasicCacheFactoryBean.CacheFactoryInitializer
called 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
- aBoolean
value to indicate whetherobjects
stored in theGemFireCache
are copied on read (i.e.Region.get(Object)
.
-
getCopyOnRead
Returns the configuration of theGemFireCache.getCopyOnRead()
property set on theGemFireCache
.- Returns:
- a
Boolean
value to indicate whetherobjects
stored in theGemFireCache
are copied on read (i.e.Region.get(Object)
.
-
isCopyOnRead
public boolean isCopyOnRead()Determines whetherobjects
stored in theGemFireCache
are copied when read (i.e.Region.get(Object)
. Defaults to false.- Returns:
- a boolean value indicating whether
objects
stored in theGemFireCache
are copied when read (i.e.Region.get(Object)
. - See Also:
-
setCriticalHeapPercentage
Set theGemFireCache
critical heap percentage property.- Parameters:
criticalHeapPercentage
-Float
value specifying the configuration for theGemFireCache
critical heap percentage.
-
getCriticalHeapPercentage
Gets the configuration of theGemFireCache
critical heap percentage property.- Returns:
- a
Float
value specifying the configuration for theGemFireCache
critical heap percentage.
-
setCriticalOffHeapPercentage
Set theGemFireCache
critical off-heap percentage property.- Parameters:
criticalOffHeapPercentage
-Float
value specifying the configuration for theGemFireCache
critical off-heap percentage.
-
getCriticalOffHeapPercentage
Gets the configuration of theGemFireCache
critical off-heap percentage property.- Returns:
- a
Float
value specifying the configuration for theGemFireCache
critical off-heap percentage.
-
setEvictionHeapPercentage
Set theGemFireCache
eviction heap percentage property.- Parameters:
evictionHeapPercentage
-Float
value specifying the configuration for theGemFireCache
eviction heap percentage.
-
getEvictionHeapPercentage
Gets the configuration of theGemFireCache
eviction heap percentage property.- Returns:
- a
Float
value specifying the configuration for theGemFireCache
eviction heap percentage.
-
setEvictionOffHeapPercentage
Set theGemFireCache
eviction off-heap percentage property.- Parameters:
evictionOffHeapPercentage
-Float
value specifying the configuration for theGemFireCache
eviction off-heap percentage.
-
getEvictionOffHeapPercentage
Gets the configuration of theGemFireCache
eviction off-heap percentage property.- Returns:
- a
Float
value specifying the configuration for theGemFireCache
eviction off-heap percentage.
-
getObject
Returns thecache object reference
created by this cacheFactoryBean
.- Specified by:
getObject
in interfaceFactoryBean<GemFireCache>
- Returns:
- the
cache object reference
created by this cacheFactoryBean
. - Throws:
Exception
- See Also:
-
doGetObject
- Returns:
- a new constructed, configured and initialized
GemFireCache
instance. - See Also:
-
getObjectType
- Specified by:
getObjectType
in interfaceFactoryBean<GemFireCache>
- Returns:
- the
type
ofGemFireCache
created by this cacheFactoryBean
. - See Also:
-
doGetObjectType
By default, returnsGemFireCache
Class
.- Returns:
GemFireCache
Class
by 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
-Boolean
value 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
Boolean
value controlling ignoring unread fields. - See Also:
-
setPdxPersistent
-
getPdxPersistent
Gets the configuration determining whethertype
metadata forobjects
serialized to PDX will be persisted to disk. -
setPdxReadSerialized
Configures whetherobjects
stored in the Apache Geodecache
as PDX will be read back as PDX bytes or (deserialized) as anObject
whenRegion.get(Object)
is called.- Parameters:
pdxReadSerialized
-Boolean
value controlling the PDX read serialized function.- See Also:
-
getPdxReadSerialized
Gets the configuration determining whetherobjects
stored in the Apache Geodecache
as PDX will be read back as PDX bytes or (deserialized) as anObject
whenRegion.get(Object)
is called.- Returns:
- a
Boolean
value controlling the PDX read serialized function. - See Also:
-
setPdxSerializer
Configures a reference toPdxSerializer
used by this cache to de/serializeobjects
stored in the cache and distributed/transferred across the distributed system as PDX bytes.- Parameters:
serializer
-PdxSerializer
used by this cache to de/serializeobjects
as PDX.- See Also:
-
getPdxSerializer
Get a reference to the configuredPdxSerializer
used by this cache to de/serializeobjects
stored 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.TYPE
value 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:
getPhase
in interfacePhased
- Returns:
- an
Integer.TYPE
used specifying the lifecycle phase for this cache bean in the Spring container. - See Also:
-
setTransactionListeners
Configures the cache (transaction manager) with aList
ofTransactionListeners
implemented by applications to listen for and receive transaction events after a transaction is processed (i.e. committed or rolled back).- Parameters:
transactionListeners
-List
of application-definedTransactionListeners
registered with the cache to listen for and receive transaction events.- See Also:
-
getTransactionListeners
Returns theList
of configured, application-definedTransactionListeners
registered 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
List
of application-definedTransactionListeners
registered with the cache (transaction manager) to listen for and receive transaction events. - See Also:
-
setTransactionWriter
Configures aTransactionWriter
implemented by the application to receive transaction events and perform a action, like a veto.- Parameters:
transactionWriter
-TransactionWriter
receiving transaction events.- See Also:
-
getTransactionWriter
Return the configuredTransactionWriter
used to process and handle transaction events.- Returns:
- the configured
TransactionWriter
. - See Also:
-
afterPropertiesSet
Initializes this cacheFactoryBean
after all properties for this cache bean have been set by the Spring container.- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Throws:
Exception
- if initialization fails.- See Also:
-
applyCacheConfigurers
protected abstract void applyCacheConfigurers()Applies any user-defined cache configurers (e.g.ClientCacheConfigurer
orPeerCacheConfigurer
) to this cacheFactoryBean
before cache construction, configuration and initialization. -
close
Null-safe method used to close theGemFireCache
by callingRegionService.close()
iff the cache is not already closed.- Parameters:
cache
-GemFireCache
to close.- See Also:
-
isNotClosed
Determines if theGemFireCache
has not been closed yet.- Parameters:
cache
-GemFireCache
to evaluate.- Returns:
- a boolean value indicating if the
GemFireCache
is not yet closed. - See Also:
-
destroy
public void destroy()Destroys the cache bean on Spring container shutdown.- Specified by:
destroy
in interfaceDisposableBean
- See Also:
-
configureHeapPercentages
Configures theGemFireCache
critical and eviction heap thresholds as percentages.- Parameters:
cache
-GemFireCache
to 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 theGemFireCache
critical and eviction off-heap thresholds as percentages.- Parameters:
cache
-GemFireCache
to 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.PdxConfigurer
used 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
- parameterizedClass
type extendingGemFireCache
.- Returns:
- an existing cache instance if available.
- Throws:
CacheClosedException
- if an existing cache instance does not exist.- See Also:
-
doFetchCache
Called byfetchCache()
if theGemFireCache
reference returned bygetCache()
is null. This method is typically implemented by callingCacheFactory.getAnyInstance()
orClientCacheFactory.getAnyInstance()
depending on theGemFireCache
type declared and used in the Spring application.- Type Parameters:
T
- parameterizedClass
type extendingGemFireCache
.- Returns:
- a (existing) reference to a
GemFireCache
instance. - Throws:
CacheClosedException
- if aGemFireCache
reference does not exist.- See Also:
-
initializeFactory
Initializes the givenCacheFactory
orClientCacheFactory
with the configuredAbstractBasicCacheFactoryBean.CacheFactoryInitializer
.- Parameters:
factory
-CacheFactory
orClientCacheFactory
to initialize.- Returns:
- the initialized
CacheFactory
orClientCacheFactory
. - See Also:
-
registerTransactionListeners
Registers configured, application-definedTransactionListeners
with 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
-GemFireCache
used to register the configured, application-definedTransactionListeners
; must not be null.- Returns:
- the given
GemFireCache
. - See Also:
-
registerTransactionWriter
Registers the configured, application-definedTransactionWriter
with the cache (transaction manager) to receive transaction events with the intent to alter the transaction outcome (e.g. veto).- Parameters:
cache
-GemFireCache
used 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 GeodeRuntimeException
into a correspondingException
from Spring's genericDataAccessException
hierarchy if possible.- Specified by:
translateExceptionIfPossible
in interfacePersistenceExceptionTranslator
- Parameters:
exception
- the Apache GeodeRuntimeException
to translate.- Returns:
- the translated Spring
DataAccessException
or null if the Apache GeodeRuntimeException
could not be translated. - See Also:
-