Class AnnotationBasedExpiration<K,V>
java.lang.Object
org.springframework.data.gemfire.expiration.AnnotationBasedExpiration<K,V>
- All Implemented Interfaces:
CacheCallback
,CustomExpiry<K,
,V> Declarable
,Aware
,BeanFactoryAware
public class AnnotationBasedExpiration<K,V>
extends Object
implements BeanFactoryAware, 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
- Author:
- John Blum
- See Also:
-
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<BeanFactory>
protected static final AtomicReference<StandardEvaluationContext>
-
Constructor Summary
ConstructorDescriptionConstructs a new instance of the AnnotationBasedExpiration class with no default expiration policy.AnnotationBasedExpiration
(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
(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
(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 BeanFactory
Gets a reference to the SpringBeanFactory
in which thisAnnotationBasedExpiration
bean is managed.protected ExpirationAttributes
Gets the expiration policy used by default when no application domain object specific expiration meta-data has been specified.protected Expiration
getExpiration
(Region.Entry<K, V> entry) Gets the Expiration Annotation meta-data from the Region Entry.getExpirationMetaData
(Region.Entry<K, V> entry) Gets custom expiration (Annotation-based) policy meta-data for the givenRegion
entry.getExpiry
(Region.Entry<K, V> entry) Calculate the expiration for a given entry.protected IdleTimeoutExpiration
getIdleTimeout
(Region.Entry<K, V> entry) Gets the IdleTimeoutExpiration Annotation meta-data from the Region Entry.protected TimeToLiveExpiration
getTimeToLive
(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
(Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the Expiration Annotation.protected boolean
isIdleTimeoutConfigured
(Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the IdleTimeoutExpiration Annotation.protected boolean
isTimeToLiveConfigured
(Region.Entry<K, V> entry) Determines whether the Region Entry has been annotated with the TimeToLiveExpiration Annotation.protected ExpirationAttributes
newExpirationAttributes
(AnnotationBasedExpiration.ExpirationMetaData expirationMetaData) Constructs a new instance ofExpirationAttributes
configured with the application domain object specific expiration policy.void
setBeanFactory
(BeanFactory beanFactory) Sets theBeanFactory
managing thisAnnotationBasedExpiration
bean in the Spring context.void
setDefaultExpirationAttributes
(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
-
EVALUATION_CONTEXT_REFERENCE
-
-
Constructor Details
-
AnnotationBasedExpiration
public AnnotationBasedExpiration()Constructs a new instance of the AnnotationBasedExpiration class with no default expiration policy. -
AnnotationBasedExpiration
Constructs a new instance ofAnnotationBasedExpiration
initialized with a specific, default expiration policy.- Parameters:
defaultExpirationAttributes
- expiration settings used as the default expiration policy.- See Also:
-
-
Method Details
-
forIdleTimeout
Factory method used to construct an instance ofAnnotationBasedExpiration
having no defaultExpirationAttributes
to process expired annotatedRegion
entries using Idle Timeout (TTI) Expiration. -
forIdleTimeout
public static <K,V> AnnotationBasedExpiration<K,V> forIdleTimeout(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. -
forTimeToLive
public static <K,V> AnnotationBasedExpiration<K,V> forTimeToLive(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
Sets theBeanFactory
managing thisAnnotationBasedExpiration
bean in the Spring context.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Parameters:
beanFactory
- the SpringBeanFactory
to which this bean belongs.- Throws:
BeansException
- if theBeanFactory
reference cannot be initialized.- See Also:
-
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:
-
setDefaultExpirationAttributes
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
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:
-
getExpiry
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 interfaceCustomExpiry<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:
-
getExpirationMetaData
protected AnnotationBasedExpiration.ExpirationMetaData getExpirationMetaData(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 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:
-
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 interfaceCacheCallback
-