Class AnnotationBasedExpiration<K,V>
java.lang.Object
org.springframework.data.gemfire.expiration.AnnotationBasedExpiration<K,V>
- All Implemented Interfaces:
org.apache.geode.cache.CacheCallback
,org.apache.geode.cache.CustomExpiry<K,
,V> org.apache.geode.cache.Declarable
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
public class AnnotationBasedExpiration<K,V>
extends Object
implements org.springframework.beans.factory.BeanFactoryAware, org.apache.geode.cache.CustomExpiry<K,V>
The
AnnotationBasedExpiration
class is an implementation of the CustomExpiry
interface
that determines the Time-To-Live (TTL) or Idle-Timeout (TTI) expiration policy of a Region
entry
by introspecting the Region
entry's class type and reflecting on any Region
entries annotated
with SDG's Expiration-based Annotations.- Since:
- 1.7.0
- See Also:
-
Annotation
BeanFactory
BeanFactoryAware
ExpirationActionType
Expiration
IdleTimeoutExpiration
TimeToLiveExpiration
CustomExpiry
ExpirationAction
ExpirationAttributes
Region
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
The ExpirationMetaData class encapsulates the settings constituting the expiration policy including the expiration timeout and the action performed when expiration occurs. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final AtomicReference<org.springframework.beans.factory.BeanFactory>
protected static final AtomicReference<org.springframework.expression.spel.support.StandardEvaluationContext>
-
Constructor Summary
ConstructorDescriptionConstructs a new instance of the AnnotationBasedExpiration class with no default expiration policy.AnnotationBasedExpiration
(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Constructs a new instance ofAnnotationBasedExpiration
initialized with a specific, default expiration policy. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Called when the Region containing this callback is closed or destroyed, when the Cache is closed, or when a callback is removed from a Region using an AttributesMutator.static <K,
V> AnnotationBasedExpiration<K, V> Factory method used to construct an instance ofAnnotationBasedExpiration
having no defaultExpirationAttributes
to process expired annotatedRegion
entries using Idle Timeout (TTI) Expiration.static <K,
V> AnnotationBasedExpiration<K, V> forIdleTimeout
(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Factory method used to construct an instance ofAnnotationBasedExpiration
initialized with defaultExpirationAttributes
to process expired annotatedRegion
entries using Idle Timeout (TTI) expiration.static <K,
V> AnnotationBasedExpiration<K, V> Factory method used to construct an instance ofAnnotationBasedExpiration
having no defaultExpirationAttributes
to process expired annotatedRegion
entries using Time-To-Live (TTL) Expiration.static <K,
V> AnnotationBasedExpiration<K, V> forTimeToLive
(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Factory method used to construct an instance ofAnnotationBasedExpiration
initialized with defaultExpirationAttributes
to process expired annotatedRegion
entries using Time-To-Live (TTL) expiration.protected org.springframework.beans.factory.BeanFactory
Gets a reference to the SpringBeanFactory
in which thisAnnotationBasedExpiration
bean is managed.protected org.apache.geode.cache.ExpirationAttributes
Gets the expiration policy used by default when no application domain object specific expiration meta-data has been specified.protected Expiration
getExpiration
(org.apache.geode.cache.Region.Entry<K, V> entry) Gets the Expiration Annotation meta-data from the Region Entry.getExpirationMetaData
(org.apache.geode.cache.Region.Entry<K, V> entry) Gets custom expiration (Annotation-based) policy meta-data for the givenRegion
entry.org.apache.geode.cache.ExpirationAttributes
Calculate the expiration for a given entry.protected IdleTimeoutExpiration
getIdleTimeout
(org.apache.geode.cache.Region.Entry<K, V> entry) Gets the IdleTimeoutExpiration Annotation meta-data from the Region Entry.protected TimeToLiveExpiration
getTimeToLive
(org.apache.geode.cache.Region.Entry<K, V> entry) Gets the TimeToLiveExpiration Annotation meta-data from the Region Entry.protected void
Initializes the Spring Expression Language (SpEL)EvaluationContext
used to parse property placeholder and SpEL expressions in the Expiration annotation attribute values.protected boolean
isExpirationConfigured
(org.apache.geode.cache.Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the Expiration Annotation.protected boolean
isIdleTimeoutConfigured
(org.apache.geode.cache.Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the IdleTimeoutExpiration Annotation.protected boolean
isTimeToLiveConfigured
(org.apache.geode.cache.Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the TimeToLiveExpiration Annotation.protected org.apache.geode.cache.ExpirationAttributes
newExpirationAttributes
(AnnotationBasedExpiration.ExpirationMetaData expirationMetaData) Constructs a new instance ofExpirationAttributes
configured with the application domain object specific expiration policy.void
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory) Sets theBeanFactory
managing thisAnnotationBasedExpiration
bean in the Spring context.void
setDefaultExpirationAttributes
(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Sets the expiration policy to use by default when no application domain object specific expiration meta-data has been specified.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.geode.cache.Declarable
init, initialize
-
Field Details
-
BEAN_FACTORY_REFERENCE
protected static final AtomicReference<org.springframework.beans.factory.BeanFactory> BEAN_FACTORY_REFERENCE -
EVALUATION_CONTEXT_REFERENCE
protected static final AtomicReference<org.springframework.expression.spel.support.StandardEvaluationContext> EVALUATION_CONTEXT_REFERENCE
-
-
Constructor Details
-
AnnotationBasedExpiration
public AnnotationBasedExpiration()Constructs a new instance of the AnnotationBasedExpiration class with no default expiration policy. -
AnnotationBasedExpiration
public AnnotationBasedExpiration(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Constructs a new instance ofAnnotationBasedExpiration
initialized with a specific, default expiration policy.- Parameters:
defaultExpirationAttributes
- expiration settings used as the default expiration policy.- See Also:
-
ExpirationAttributes
-
-
Method Details
-
forIdleTimeout
Factory method used to construct an instance ofAnnotationBasedExpiration
having no defaultExpirationAttributes
to process expired annotatedRegion
entries using Idle Timeout (TTI) Expiration.- Type Parameters:
K
-Class
type of theRegion
entry key.V
-Class
type of theRegion
entry value.- Returns:
- an
AnnotationBasedExpiration
instance to process expired annotatedRegion
entries using Idle Timeout expiration. - See Also:
-
forIdleTimeout
public static <K,V> AnnotationBasedExpiration<K,V> forIdleTimeout(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Factory method used to construct an instance ofAnnotationBasedExpiration
initialized with defaultExpirationAttributes
to process expired annotatedRegion
entries using Idle Timeout (TTI) expiration.- Type Parameters:
K
-Class
type of theRegion
entry key.V
-Class
type of theRegion
entry value.- Parameters:
defaultExpirationAttributes
-ExpirationAttributes
used by default if no expiration policy was specified on theRegion
.- Returns:
- an
AnnotationBasedExpiration
instance to process expired annotatedRegion
entries using Idle Timeout expiration. - See Also:
-
forTimeToLive
Factory method used to construct an instance ofAnnotationBasedExpiration
having no defaultExpirationAttributes
to process expired annotatedRegion
entries using Time-To-Live (TTL) Expiration.- Type Parameters:
K
-Class
type of theRegion
entry key.V
-Class
type of theRegion
entry value.- Returns:
- an
AnnotationBasedExpiration
instance to process expired annotatedRegion
entries using Time-To-Live expiration. - See Also:
-
forTimeToLive
public static <K,V> AnnotationBasedExpiration<K,V> forTimeToLive(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Factory method used to construct an instance ofAnnotationBasedExpiration
initialized with defaultExpirationAttributes
to process expired annotatedRegion
entries using Time-To-Live (TTL) expiration.- Type Parameters:
K
-Class
type of theRegion
entry key.V
-Class
type of theRegion
entry value.- Parameters:
defaultExpirationAttributes
-ExpirationAttributes
used by default if no expiration policy was specified on theRegion
.- Returns:
- an
AnnotationBasedExpiration
instance to process expired annotatedRegion
entries using Time-To-Live expiration. - See Also:
-
initEvaluationContext
protected void initEvaluationContext()Initializes the Spring Expression Language (SpEL)EvaluationContext
used to parse property placeholder and SpEL expressions in the Expiration annotation attribute values. -
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException Sets theBeanFactory
managing thisAnnotationBasedExpiration
bean in the Spring context.- Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
- Parameters:
beanFactory
- the SpringBeanFactory
to which this bean belongs.- Throws:
org.springframework.beans.BeansException
- if theBeanFactory
reference cannot be initialized.- See Also:
-
BeanFactory
initEvaluationContext()
-
getBeanFactory
protected org.springframework.beans.factory.BeanFactory getBeanFactory()Gets a reference to the SpringBeanFactory
in which thisAnnotationBasedExpiration
bean is managed.- Returns:
- a reference to the Spring
BeanFactory
. - Throws:
IllegalStateException
- if theBeanFactory
reference was not properly initialized.- See Also:
-
BeanFactory
-
setDefaultExpirationAttributes
public void setDefaultExpirationAttributes(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Sets the expiration policy to use by default when no application domain object specific expiration meta-data has been specified.- Parameters:
defaultExpirationAttributes
- expiration settings used as the default expiration policy.- See Also:
-
getDefaultExpirationAttributes()
ExpirationAttributes
-
getDefaultExpirationAttributes
protected org.apache.geode.cache.ExpirationAttributes getDefaultExpirationAttributes()Gets the expiration policy used by default when no application domain object specific expiration meta-data has been specified.- Returns:
- an instance of ExpirationAttributes with expiration settings defining the default expiration policy.
- See Also:
-
setDefaultExpirationAttributes(ExpirationAttributes)
ExpirationAttributes
-
getExpiry
public org.apache.geode.cache.ExpirationAttributes getExpiry(org.apache.geode.cache.Region.Entry<K, V> entry) Calculate the expiration for a given entry. Returning null indicates that the default for theRegion
should be used. The entry parameter should not be used after this method invocation completes.- Specified by:
getExpiry
in interfaceorg.apache.geode.cache.CustomExpiry<K,
V> - Parameters:
entry
- the entry used to determine the appropriate expiration policy.- Returns:
- the expiration configuration to be used or null if the Region's defaults should be used.
- See Also:
-
ExpirationAttributes
Region
getExpirationMetaData(Region.Entry)
newExpirationAttributes(ExpirationMetaData)
-
getExpirationMetaData
protected AnnotationBasedExpiration.ExpirationMetaData getExpirationMetaData(org.apache.geode.cache.Region.Entry<K, V> entry) Gets custom expiration (Annotation-based) policy meta-data for the givenRegion
entry.- Parameters:
entry
-Region
entry used as the source of the expiration policy meta-data.- Returns:
AnnotationBasedExpiration.ExpirationMetaData
extracted from theRegion
entry or null if the expiration policy meta-data could not be determined from theRegion
entry.- See Also:
-
newExpirationAttributes
protected org.apache.geode.cache.ExpirationAttributes newExpirationAttributes(AnnotationBasedExpiration.ExpirationMetaData expirationMetaData) Constructs a new instance ofExpirationAttributes
configured with the application domain object specific expiration policy. If the application domain object type has not been annotated with custom expiration meta-data, then the default expiration settings are used.- Parameters:
expirationMetaData
- application domain object specific expiration policy meta-data used to construct theExpirationAttributes
.- Returns:
- custom
ExpirationAttributes
configured from the application domain object specific expiration policy or the default expiration settings if the application domain object has not been annotated with custom expiration meta-data. - See Also:
-
AnnotationBasedExpiration.ExpirationMetaData
ExpirationAttributes
getDefaultExpirationAttributes()
-
isExpirationConfigured
Determines whether the Region Entry has been annotated with the Expiration Annotation.- Parameters:
entry
- the Region.Entry to evaluate for the presence of the Expiration Annotation.- Returns:
- a boolean value indicating whether the Region Entry has been annotated with @Expiration.
- See Also:
-
Expiration
isAnnotationPresent(Object, Class)
-
getExpiration
Gets the Expiration Annotation meta-data from the Region Entry.- Parameters:
entry
- the Region.Entry from which to extract the Expiration Annotation meta-data.- Returns:
- the Expiration Annotation meta-data for the given Region Entry or
null
if the Region Entry has not been annotated with @Expiration. - See Also:
-
Expiration
getAnnotation(Object, Class)
-
isIdleTimeoutConfigured
Determines whether the Region Entry has been annotated with the IdleTimeoutExpiration Annotation.- Parameters:
entry
- the Region.Entry to evaluate for the presence of the IdleTimeoutExpiration Annotation.- Returns:
- a boolean value indicating whether the Region Entry has been annotated with @IdleTimeoutExpiration.
- See Also:
-
IdleTimeoutExpiration
isAnnotationPresent(Object, Class)
-
getIdleTimeout
Gets the IdleTimeoutExpiration Annotation meta-data from the Region Entry.- Parameters:
entry
- the Region.Entry from which to extract the IdleTimeoutExpiration Annotation meta-data.- Returns:
- the IdleTimeoutExpiration Annotation meta-data for the given Region Entry or
null
if the Region Entry has not been annotated with @IdleTimeoutExpiration. - See Also:
-
IdleTimeoutExpiration
getAnnotation(Object, Class)
-
isTimeToLiveConfigured
Determines whether the Region Entry has been annotated with the TimeToLiveExpiration Annotation.- Parameters:
entry
- the Region.Entry to evaluate for the presence of the TimeToLiveExpiration Annotation.- Returns:
- a boolean value indicating whether the Region Entry has been annotated with @TimeToLiveExpiration.
- See Also:
-
TimeToLiveExpiration
isAnnotationPresent(Object, Class)
-
getTimeToLive
Gets the TimeToLiveExpiration Annotation meta-data from the Region Entry.- Parameters:
entry
- the Region.Entry from which to extract the TimeToLiveExpiration Annotation meta-data.- Returns:
- the TimeToLiveExpiration Annotation meta-data for the given Region Entry or
null
if the Region Entry has not been annotated with @TimeToLiveExpiration. - See Also:
-
TimeToLiveExpiration
getAnnotation(Object, Class)
-
close
public void close()Called when the Region containing this callback is closed or destroyed, when the Cache is closed, or when a callback is removed from a Region using an AttributesMutator.- Specified by:
close
in interfaceorg.apache.geode.cache.CacheCallback
-