public abstract class AbstractBasicCacheFactoryBean extends AbstractFactoryBeanSupport<org.apache.geode.cache.GemFireCache> implements DisposableBean, InitializingBean, PersistenceExceptionTranslator, Phased
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:
ClientCache and peer Cache instances.GemFireCheckedException,
GemFireException,
Cache,
CacheFactory,
GemFireCache,
Region,
TransactionListener,
TransactionWriter,
ClientCache,
ClientCacheFactory,
PdxSerializer,
DisposableBean,
FactoryBean,
InitializingBean,
Phased,
DataAccessException,
PersistenceExceptionTranslationPostProcessor,
PersistenceExceptionTranslator,
CacheFactoryBean,
ClientCacheFactoryBean,
ClientCacheConfigurer,
PeerCacheConfigurer,
AbstractFactoryBeanSupport| Modifier and Type | Class and Description |
|---|---|
static interface |
AbstractBasicCacheFactoryBean.CacheFactoryInitializer<T>
Callback interface for initializing a
CacheFactory or a ClientCacheFactory instance,
which is used to create an instance of GemFireCache. |
static interface |
AbstractBasicCacheFactoryBean.PdxConfigurer<T>
Callback interface to configure PDX.
|
DEFAULT_SINGLETONOBJECT_TYPE_ATTRIBUTE| Constructor and Description |
|---|
AbstractBasicCacheFactoryBean() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Initializes this cache
FactoryBean after all properties for this cache bean have been set
by the Spring container. |
protected abstract void |
applyCacheConfigurers()
Applies any user-defined cache configurers (e.g.
|
protected void |
close(org.apache.geode.cache.GemFireCache cache)
Null-safe method used to close the
GemFireCache by calling RegionService.close()
iff the cache is not already closed. |
protected org.apache.geode.cache.GemFireCache |
configureHeapPercentages(org.apache.geode.cache.GemFireCache cache)
Configures the
GemFireCache critical and eviction heap thresholds as percentages. |
protected org.apache.geode.cache.GemFireCache |
configureOffHeapPercentages(org.apache.geode.cache.GemFireCache cache)
Configures the
GemFireCache 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 org.apache.geode.cache.GemFireCache> |
doFetchCache()
|
protected abstract org.apache.geode.cache.GemFireCache |
doGetObject()
|
protected Class<? extends org.apache.geode.cache.GemFireCache> |
doGetObjectType()
By default, returns
GemFireCache Class. |
protected <T extends org.apache.geode.cache.GemFireCache> |
fetchCache()
Fetches an existing cache instance from the Apache Geode cache factory.
|
<T extends org.apache.geode.cache.GemFireCache> |
getCache()
Returns a reference to the constructed, configured an initialized
GemFireCache instance created by
this cache FactoryBean. |
AbstractBasicCacheFactoryBean.CacheFactoryInitializer |
getCacheFactoryInitializer()
Return the
AbstractBasicCacheFactoryBean.CacheFactoryInitializer called by this FactoryBean to initialize the Apache Geode
cache factory used to create the cache constructed by this FactoryBean. |
Boolean |
getCopyOnRead()
Returns the configuration of the
GemFireCache.getCopyOnRead() property set on the GemFireCache. |
Float |
getCriticalHeapPercentage()
Gets the configuration of the
GemFireCache critical heap percentage property. |
Float |
getCriticalOffHeapPercentage()
Gets the configuration of the
GemFireCache critical off-heap percentage property. |
Float |
getEvictionHeapPercentage()
Gets the configuration of the
GemFireCache eviction heap percentage property. |
Float |
getEvictionOffHeapPercentage()
Gets the configuration of the
GemFireCache eviction off-heap percentage property. |
org.apache.geode.cache.GemFireCache |
getObject()
Returns the
cache object reference created by this cache FactoryBean. |
Class<? extends org.apache.geode.cache.GemFireCache> |
getObjectType()
|
<T extends org.apache.geode.cache.GemFireCache> |
getOptionalCache()
Returns an
Optional reference to the constructed, configured and initialized GemFireCache
instance created by this cache FactoryBean. |
String |
getPdxDiskStoreName()
Gets the
name of the Apache Geode DiskStore used to store PDX metadata. |
Boolean |
getPdxIgnoreUnreadFields()
Gets the configuration determining whether PDX will ignore unread fields when deserializing PDX bytes
back to an
Object. |
Boolean |
getPdxPersistent()
|
Boolean |
getPdxReadSerialized()
|
org.apache.geode.pdx.PdxSerializer |
getPdxSerializer()
Get a reference to the configured
PdxSerializer used by this cache to de/serialize objects
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.
|
List<org.apache.geode.cache.TransactionListener> |
getTransactionListeners()
Returns the
List of configured, application-defined TransactionListeners
registered with the cache (transaction manager) to enable applications to receive transaction events after a
transaction is processed (i.e. committed or rolled back). |
org.apache.geode.cache.TransactionWriter |
getTransactionWriter()
Return the configured
TransactionWriter used to process and handle transaction events. |
protected Object |
initializeFactory(Object factory)
Initializes the given
CacheFactory or ClientCacheFactory
with the configured AbstractBasicCacheFactoryBean.CacheFactoryInitializer. |
boolean |
isClose()
Returns a boolean value used to determine whether the cache will be closed on shutdown of the Spring container.
|
boolean |
isCopyOnRead()
Determines whether
objects stored in the GemFireCache are copied when read
(i.e. |
protected org.apache.geode.cache.GemFireCache |
registerTransactionListeners(org.apache.geode.cache.GemFireCache cache)
Registers configured, application-defined
TransactionListeners 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 org.apache.geode.cache.GemFireCache |
registerTransactionWriter(org.apache.geode.cache.GemFireCache cache)
Registers the configured, application-defined
TransactionWriter with the cache (transaction manager)
to receive transaction events with the intent to alter the transaction outcome (e.g. veto). |
protected void |
setCache(org.apache.geode.cache.GemFireCache cache)
Sets a reference to the constructed, configured an initialized
GemFireCache instance created by
this cache FactoryBean. |
void |
setCacheFactoryInitializer(AbstractBasicCacheFactoryBean.CacheFactoryInitializer cacheFactoryInitializer)
Set the
AbstractBasicCacheFactoryBean.CacheFactoryInitializer called by this FactoryBean to initialize the Apache Geode
cache factory used to create the cache constructed by this FactoryBean. |
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 the
GemFireCache.getCopyOnRead() property of the GemFireCache. |
void |
setCriticalHeapPercentage(Float criticalHeapPercentage)
Set the
GemFireCache critical heap percentage property. |
void |
setCriticalOffHeapPercentage(Float criticalOffHeapPercentage)
Set the
GemFireCache critical off-heap percentage property. |
void |
setEvictionHeapPercentage(Float evictionHeapPercentage)
Set the
GemFireCache eviction heap percentage property. |
void |
setEvictionOffHeapPercentage(Float evictionOffHeapPercentage)
Set the
GemFireCache eviction off-heap percentage property. |
void |
setPdxDiskStoreName(String pdxDiskStoreName)
Sets the
name of the Apache Geode DiskStore used to store PDX metadata. |
void |
setPdxIgnoreUnreadFields(Boolean pdxIgnoreUnreadFields)
Configures whether PDX will ignore unread fields when deserializing PDX bytes back to an
Object. |
void |
setPdxPersistent(Boolean pdxPersistent)
|
void |
setPdxReadSerialized(Boolean pdxReadSerialized)
|
void |
setPdxSerializer(org.apache.geode.pdx.PdxSerializer serializer)
Configures a reference to
PdxSerializer used by this cache to de/serialize objects
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<org.apache.geode.cache.TransactionListener> transactionListeners)
Configures the cache (transaction manager) with a
List of TransactionListeners
implemented by applications to listen for and receive transaction events after a transaction is processed
(i.e. committed or rolled back). |
void |
setTransactionWriter(org.apache.geode.cache.TransactionWriter transactionWriter)
Configures a
TransactionWriter implemented by the application to receive transaction events and perform
a action, like a veto. |
DataAccessException |
translateExceptionIfPossible(RuntimeException exception)
Translates the thrown Apache Geode
RuntimeException into a corresponding Exception from Spring's
generic DataAccessException hierarchy if possible. |
getBeanClassLoader, getBeanFactory, getBeanName, getLog, isSingleton, logDebug, logDebug, logError, logError, logInfo, logInfo, logWarning, logWarning, newLog, setBeanClassLoader, setBeanFactory, setBeanNameprotected void setCache(@Nullable org.apache.geode.cache.GemFireCache cache)
GemFireCache instance created by
this cache FactoryBean.cache - GemFireCache created by this cache FactoryBean.GemFireCache@Nullable public <T extends org.apache.geode.cache.GemFireCache> T getCache()
GemFireCache instance created by
this cache FactoryBean.T - parameterized Class type extending GemFireCache.GemFireCache created by this cache FactoryBean.GemFireCachepublic <T extends org.apache.geode.cache.GemFireCache> Optional<T> getOptionalCache()
Optional reference to the constructed, configured and initialized GemFireCache
instance created by this cache FactoryBean.T - parameterized Class type extending GemFireCache.Optional reference to the GemFireCache created by this {cache @link FactoryBean}.GemFireCache,
Optional,
getCache()public void setCacheFactoryInitializer(@Nullable AbstractBasicCacheFactoryBean.CacheFactoryInitializer cacheFactoryInitializer)
AbstractBasicCacheFactoryBean.CacheFactoryInitializer called by this FactoryBean to initialize the Apache Geode
cache factory used to create the cache constructed by this FactoryBean.cacheFactoryInitializer - AbstractBasicCacheFactoryBean.CacheFactoryInitializer called to initialize the cache factory.org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializer@Nullable public AbstractBasicCacheFactoryBean.CacheFactoryInitializer getCacheFactoryInitializer()
AbstractBasicCacheFactoryBean.CacheFactoryInitializer called by this FactoryBean to initialize the Apache Geode
cache factory used to create the cache constructed by this FactoryBean.AbstractBasicCacheFactoryBean.CacheFactoryInitializer called to initialize the cache factory.org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializerpublic void setClose(boolean close)
close - boolean value used to determine whether the cache will be closed on shutdown of the Spring container.public boolean isClose()
public void setCopyOnRead(@Nullable Boolean copyOnRead)
GemFireCache.getCopyOnRead() property of the GemFireCache.@Nullable public Boolean getCopyOnRead()
GemFireCache.getCopyOnRead() property set on the GemFireCache.public boolean isCopyOnRead()
objects stored in the GemFireCache are copied when read
(i.e. Region.get(Object).
Defaults to false.objects stored in the GemFireCache
are copied when read (i.e. Region.get(Object).getCopyOnRead()public void setCriticalHeapPercentage(@Nullable Float criticalHeapPercentage)
GemFireCache critical heap percentage property.criticalHeapPercentage - Float value specifying the configuration for the GemFireCache
critical heap percentage.public Float getCriticalHeapPercentage()
GemFireCache critical heap percentage property.Float value specifying the configuration for the GemFireCache critical heap percentage.public void setCriticalOffHeapPercentage(@Nullable Float criticalOffHeapPercentage)
GemFireCache critical off-heap percentage property.criticalOffHeapPercentage - Float value specifying the configuration for the GemFireCache
critical off-heap percentage.public Float getCriticalOffHeapPercentage()
GemFireCache critical off-heap percentage property.Float value specifying the configuration for the GemFireCache critical off-heap
percentage.public void setEvictionHeapPercentage(Float evictionHeapPercentage)
GemFireCache eviction heap percentage property.evictionHeapPercentage - Float value specifying the configuration for the GemFireCache
eviction heap percentage.public Float getEvictionHeapPercentage()
GemFireCache eviction heap percentage property.Float value specifying the configuration for the GemFireCache eviction heap percentage.public void setEvictionOffHeapPercentage(Float evictionOffHeapPercentage)
GemFireCache eviction off-heap percentage property.evictionOffHeapPercentage - Float value specifying the configuration for the GemFireCache
eviction off-heap percentage.public Float getEvictionOffHeapPercentage()
GemFireCache eviction off-heap percentage property.Float value specifying the configuration for the GemFireCache eviction off-heap
percentage.public org.apache.geode.cache.GemFireCache getObject()
throws Exception
cache object reference created by this cache FactoryBean.getObject in interface FactoryBean<org.apache.geode.cache.GemFireCache>cache object reference created by this cache FactoryBean.ExceptionFactoryBean.getObject(),
GemFireCache,
doGetObject(),
getCache()protected abstract org.apache.geode.cache.GemFireCache doGetObject()
GemFireCache instance.GemFireCache,
getObject()public Class<? extends org.apache.geode.cache.GemFireCache> getObjectType()
getObjectType in interface FactoryBean<org.apache.geode.cache.GemFireCache>type of GemFireCache created by this cache FactoryBean.FactoryBean.getObjectType(),
doGetObjectType()protected Class<? extends org.apache.geode.cache.GemFireCache> doGetObjectType()
GemFireCache Class.GemFireCache Class by default.org.apache.geode.cache.GemFireCache#getClass(),
getObjectType(),
Classpublic void setPdxDiskStoreName(@Nullable String pdxDiskStoreName)
name of the Apache Geode DiskStore used to store PDX metadata.pdxDiskStoreName - name for the PDX DiskStore.CacheFactory.setPdxDiskStore(String),
DiskStore.getName()@Nullable public String getPdxDiskStoreName()
name of the Apache Geode DiskStore used to store PDX metadata.name of the PDX DiskStore.GemFireCache.getPdxDiskStore(),
DiskStore.getName()public void setPdxIgnoreUnreadFields(@Nullable Boolean pdxIgnoreUnreadFields)
Object.
Defaults to false.pdxIgnoreUnreadFields - Boolean value controlling ignoring unread fields.CacheFactory.setPdxIgnoreUnreadFields(boolean)@Nullable public Boolean getPdxIgnoreUnreadFields()
Object.
Defaults to false.Boolean value controlling ignoring unread fields.GemFireCache.getPdxIgnoreUnreadFields()public void setPdxReadSerialized(@Nullable Boolean pdxReadSerialized)
objects stored in the Apache Geode cache as PDX
will be read back as PDX bytes or (deserialized) as an Object when Region.get(Object)
is called.pdxReadSerialized - Boolean value controlling the PDX read serialized function.CacheFactory.setPdxReadSerialized(boolean)@Nullable public Boolean getPdxReadSerialized()
objects stored in the Apache Geode
cache as PDX will be read back as PDX bytes or (deserialized) as an Object
when Region.get(Object) is called.Boolean value controlling the PDX read serialized function.GemFireCache.getPdxReadSerialized()public void setPdxSerializer(@Nullable org.apache.geode.pdx.PdxSerializer serializer)
PdxSerializer used by this cache to de/serialize objects
stored in the cache and distributed/transferred across the distributed system as PDX bytes.serializer - PdxSerializer used by this cache to de/serialize objects as PDX.CacheFactory.setPdxSerializer(PdxSerializer),
PdxSerializer@Nullable public org.apache.geode.pdx.PdxSerializer getPdxSerializer()
PdxSerializer used by this cache to de/serialize objects
stored in the cache and distributed/transferred across the distributed system as PDX bytes.PdxSerializer.GemFireCache.getPdxSerializer(),
PdxSerializerprotected void setPhase(int phase)
phase - Integer.TYPE value specifying the lifecycle phase for this cache bean
in the Spring container.Phased.getPhase()public int getPhase()
getPhase in interface PhasedInteger.TYPE used specifying the lifecycle phase for this cache bean in the Spring container.Phased.getPhase()public void setTransactionListeners(List<org.apache.geode.cache.TransactionListener> transactionListeners)
List of TransactionListeners
implemented by applications to listen for and receive transaction events after a transaction is processed
(i.e. committed or rolled back).transactionListeners - List of application-defined TransactionListeners
registered with the cache to listen for and receive transaction events.TransactionListenerpublic List<org.apache.geode.cache.TransactionListener> getTransactionListeners()
List of configured, application-defined TransactionListeners
registered with the cache (transaction manager) to enable applications to receive transaction events after a
transaction is processed (i.e. committed or rolled back).List of application-defined TransactionListeners registered with
the cache (transaction manager) to listen for and receive transaction events.TransactionListenerpublic void setTransactionWriter(@Nullable org.apache.geode.cache.TransactionWriter transactionWriter)
TransactionWriter implemented by the application to receive transaction events and perform
a action, like a veto.transactionWriter - TransactionWriter receiving transaction events.TransactionWriter@Nullable public org.apache.geode.cache.TransactionWriter getTransactionWriter()
TransactionWriter used to process and handle transaction events.TransactionWriter.TransactionWriterpublic void afterPropertiesSet()
throws Exception
FactoryBean after all properties for this cache bean have been set
by the Spring container.afterPropertiesSet in interface InitializingBeanException - if initialization fails.InitializingBean.afterPropertiesSet(),
applyCacheConfigurers()protected abstract void applyCacheConfigurers()
ClientCacheConfigurer or PeerCacheConfigurer)
to this cache FactoryBean before cache construction, configuration and initialization.protected void close(@Nullable org.apache.geode.cache.GemFireCache cache)
GemFireCache by calling RegionService.close()
iff the cache is not already closed.cache - GemFireCache to close.RegionService.isClosed(),
RegionService.close()public void destroy()
destroy in interface DisposableBeanDisposableBean.destroy(),
close(GemFireCache),
fetchCache(),
isClose()@NonNull protected org.apache.geode.cache.GemFireCache configureHeapPercentages(@NonNull org.apache.geode.cache.GemFireCache cache)
GemFireCache critical and eviction heap thresholds as percentages.cache - GemFireCache to configure the critical and eviction heap thresholds;
must not be null.GemFireCache.IllegalArgumentException - if the critical or eviction heap thresholds are not valid percentages.ResourceManager.setCriticalHeapPercentage(float),
ResourceManager.setEvictionHeapPercentage(float),
ResourceManager,
GemFireCache.getResourceManager(),
GemFireCache@NonNull protected org.apache.geode.cache.GemFireCache configureOffHeapPercentages(@NonNull org.apache.geode.cache.GemFireCache cache)
GemFireCache critical and eviction off-heap thresholds as percentages.cache - GemFireCache to configure the critical and eviction off-heap thresholds;
must not be null.GemFireCache.IllegalArgumentException - if the critical or eviction off-heap thresholds are not valid percentages.ResourceManager.setCriticalOffHeapPercentage(float),
ResourceManager.setEvictionOffHeapPercentage(float),
ResourceManager,
GemFireCache.getResourceManager(),
GemFireCacheprotected <T> T configurePdx(AbstractBasicCacheFactoryBean.PdxConfigurer<T> pdxConfigurer)
pdxConfigurer - AbstractBasicCacheFactoryBean.PdxConfigurer used to configure the cache with PDX serialization.AbstractBasicCacheFactoryBean.PdxConfigurer.getTarget().protected <T extends org.apache.geode.cache.GemFireCache> T fetchCache()
T - parameterized Class type extending GemFireCache.org.apache.geode.cache.CacheClosedException - if an existing cache instance does not exist.ClientCacheFactory.getAnyInstance(),
CacheFactory.getAnyInstance(),
GemFireCache,
doFetchCache(),
getCache()protected abstract <T extends org.apache.geode.cache.GemFireCache> T doFetchCache()
fetchCache() if the GemFireCache reference returned by getCache()
is null.
This method is typically implemented by calling CacheFactory.getAnyInstance()
or ClientCacheFactory.getAnyInstance() depending on the GemFireCache type declared
and used in the Spring application.T - parameterized Class type extending GemFireCache.GemFireCache instance.org.apache.geode.cache.CacheClosedException - if a GemFireCache reference does not exist.fetchCache()@Nullable protected Object initializeFactory(Object factory)
CacheFactory or ClientCacheFactory
with the configured AbstractBasicCacheFactoryBean.CacheFactoryInitializer.factory - CacheFactory or ClientCacheFactory to initialize.CacheFactory or ClientCacheFactory.org.springframework.data.gemfire.CacheFactoryBean.CacheFactoryInitializer#initialize(Object),
ClientCacheFactory,
CacheFactory,
getCacheFactoryInitializer()@NonNull protected org.apache.geode.cache.GemFireCache registerTransactionListeners(@NonNull org.apache.geode.cache.GemFireCache cache)
TransactionListeners with the cache
(transaction manager) to listen for and receive transaction events when a (cache) transaction is processed
(e.g. committed or rolled back).cache - GemFireCache used to register the configured, application-defined
TransactionListeners; must not be null.GemFireCache.GemFireCache.getCacheTransactionManager(),
CacheTransactionManager.addListener(TransactionListener),
CacheTransactionManager,
TransactionListener,
GemFireCache@NonNull protected org.apache.geode.cache.GemFireCache registerTransactionWriter(@NonNull org.apache.geode.cache.GemFireCache cache)
TransactionWriter with the cache (transaction manager)
to receive transaction events with the intent to alter the transaction outcome (e.g. veto).cache - GemFireCache used to register the configured, application-defined TransactionWriter,
must not be null.GemFireCache.GemFireCache.getCacheTransactionManager(),
CacheTransactionManager.setWriter(TransactionWriter),
CacheTransactionManager,
TransactionWriter,
GemFireCache@Nullable public DataAccessException translateExceptionIfPossible(@Nullable RuntimeException exception)
RuntimeException into a corresponding Exception from Spring's
generic DataAccessException hierarchy if possible.translateExceptionIfPossible in interface PersistenceExceptionTranslatorexception - the Apache Geode RuntimeException to translate.DataAccessException or null
if the Apache Geode RuntimeException could not be translated.PersistenceExceptionTranslator.translateExceptionIfPossible(RuntimeException),
DataAccessExceptionCopyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.