Spring Data for VMware GemFire
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:
-
AnnotationBeanFactoryBeanFactoryAwareExpirationActionTypeExpirationIdleTimeoutExpirationTimeToLiveExpirationCustomExpiryExpirationActionExpirationAttributesRegion
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThe ExpirationMetaData class encapsulates the settings constituting the expiration policy including the expiration timeout and the action performed when expiration occurs. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final AtomicReference<org.springframework.beans.factory.BeanFactory>protected static final AtomicReference<org.springframework.expression.spel.support.StandardEvaluationContext> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of the AnnotationBasedExpiration class with no default expiration policy.AnnotationBasedExpiration(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes) Constructs a new instance ofAnnotationBasedExpirationinitialized with a specific, default expiration policy. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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 ofAnnotationBasedExpirationhaving no defaultExpirationAttributesto process expired annotatedRegionentries 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 ofAnnotationBasedExpirationinitialized with defaultExpirationAttributesto process expired annotatedRegionentries using Idle Timeout (TTI) expiration.static <K,V> AnnotationBasedExpiration<K, V> Factory method used to construct an instance ofAnnotationBasedExpirationhaving no defaultExpirationAttributesto process expired annotatedRegionentries 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 ofAnnotationBasedExpirationinitialized with defaultExpirationAttributesto process expired annotatedRegionentries using Time-To-Live (TTL) expiration.protected org.springframework.beans.factory.BeanFactoryGets a reference to the SpringBeanFactoryin which thisAnnotationBasedExpirationbean is managed.protected org.apache.geode.cache.ExpirationAttributesGets the expiration policy used by default when no application domain object specific expiration meta-data has been specified.protected ExpirationgetExpiration(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 givenRegionentry.org.apache.geode.cache.ExpirationAttributesCalculate the expiration for a given entry.protected IdleTimeoutExpirationgetIdleTimeout(org.apache.geode.cache.Region.Entry<K, V> entry) Gets the IdleTimeoutExpiration Annotation meta-data from the Region Entry.protected TimeToLiveExpirationgetTimeToLive(org.apache.geode.cache.Region.Entry<K, V> entry) Gets the TimeToLiveExpiration Annotation meta-data from the Region Entry.protected voidInitializes the Spring Expression Language (SpEL)EvaluationContextused to parse property placeholder and SpEL expressions in the Expiration annotation attribute values.protected booleanisExpirationConfigured(org.apache.geode.cache.Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the Expiration Annotation.protected booleanisIdleTimeoutConfigured(org.apache.geode.cache.Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the IdleTimeoutExpiration Annotation.protected booleanisTimeToLiveConfigured(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.ExpirationAttributesnewExpirationAttributes(AnnotationBasedExpiration.ExpirationMetaData expirationMetaData) Constructs a new instance ofExpirationAttributesconfigured with the application domain object specific expiration policy.voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Sets theBeanFactorymanaging thisAnnotationBasedExpirationbean in the Spring context.voidsetDefaultExpirationAttributes(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, waitMethods 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 ofAnnotationBasedExpirationinitialized 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 ofAnnotationBasedExpirationhaving no defaultExpirationAttributesto process expired annotatedRegionentries using Idle Timeout (TTI) Expiration.- Type Parameters:
K-Classtype of theRegionentry key.V-Classtype of theRegionentry value.- Returns:
- an
AnnotationBasedExpirationinstance to process expired annotatedRegionentries 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 ofAnnotationBasedExpirationinitialized with defaultExpirationAttributesto process expired annotatedRegionentries using Idle Timeout (TTI) expiration.- Type Parameters:
K-Classtype of theRegionentry key.V-Classtype of theRegionentry value.- Parameters:
defaultExpirationAttributes-ExpirationAttributesused by default if no expiration policy was specified on theRegion.- Returns:
- an
AnnotationBasedExpirationinstance to process expired annotatedRegionentries using Idle Timeout expiration. - See Also:
-
forTimeToLive
Factory method used to construct an instance ofAnnotationBasedExpirationhaving no defaultExpirationAttributesto process expired annotatedRegionentries using Time-To-Live (TTL) Expiration.- Type Parameters:
K-Classtype of theRegionentry key.V-Classtype of theRegionentry value.- Returns:
- an
AnnotationBasedExpirationinstance to process expired annotatedRegionentries 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 ofAnnotationBasedExpirationinitialized with defaultExpirationAttributesto process expired annotatedRegionentries using Time-To-Live (TTL) expiration.- Type Parameters:
K-Classtype of theRegionentry key.V-Classtype of theRegionentry value.- Parameters:
defaultExpirationAttributes-ExpirationAttributesused by default if no expiration policy was specified on theRegion.- Returns:
- an
AnnotationBasedExpirationinstance to process expired annotatedRegionentries using Time-To-Live expiration. - See Also:
-
initEvaluationContext
protected void initEvaluationContext()Initializes the Spring Expression Language (SpEL)EvaluationContextused 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 theBeanFactorymanaging thisAnnotationBasedExpirationbean in the Spring context.- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Parameters:
beanFactory- the SpringBeanFactoryto which this bean belongs.- Throws:
org.springframework.beans.BeansException- if theBeanFactoryreference cannot be initialized.- See Also:
-
BeanFactoryinitEvaluationContext()
-
getBeanFactory
protected org.springframework.beans.factory.BeanFactory getBeanFactory()Gets a reference to the SpringBeanFactoryin which thisAnnotationBasedExpirationbean is managed.- Returns:
- a reference to the Spring
BeanFactory. - Throws:
IllegalStateException- if theBeanFactoryreference 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 theRegionshould be used. The entry parameter should not be used after this method invocation completes.- Specified by:
getExpiryin 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:
-
ExpirationAttributesRegiongetExpirationMetaData(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 givenRegionentry.- Parameters:
entry-Regionentry used as the source of the expiration policy meta-data.- Returns:
AnnotationBasedExpiration.ExpirationMetaDataextracted from theRegionentry or null if the expiration policy meta-data could not be determined from theRegionentry.- See Also:
-
newExpirationAttributes
protected org.apache.geode.cache.ExpirationAttributes newExpirationAttributes(AnnotationBasedExpiration.ExpirationMetaData expirationMetaData) Constructs a new instance ofExpirationAttributesconfigured 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
ExpirationAttributesconfigured 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.ExpirationMetaDataExpirationAttributesgetDefaultExpirationAttributes()
-
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:
-
ExpirationisAnnotationPresent(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
nullif the Region Entry has not been annotated with @Expiration. - See Also:
-
ExpirationgetAnnotation(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:
-
IdleTimeoutExpirationisAnnotationPresent(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
nullif the Region Entry has not been annotated with @IdleTimeoutExpiration. - See Also:
-
IdleTimeoutExpirationgetAnnotation(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:
-
TimeToLiveExpirationisAnnotationPresent(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
nullif the Region Entry has not been annotated with @TimeToLiveExpiration. - See Also:
-
TimeToLiveExpirationgetAnnotation(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:
closein interfaceorg.apache.geode.cache.CacheCallback
-