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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected 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

    Fields
    Modifier and Type
    Field
    Description
    protected static final AtomicReference<org.springframework.beans.factory.BeanFactory>
     
    protected static final AtomicReference<org.springframework.expression.spel.support.StandardEvaluationContext>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new instance of the AnnotationBasedExpiration class with no default expiration policy.
    AnnotationBasedExpiration(org.apache.geode.cache.ExpirationAttributes defaultExpirationAttributes)
    Constructs a new instance of AnnotationBasedExpiration initialized with a specific, default expiration policy.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 of AnnotationBasedExpiration having no default ExpirationAttributes to process expired annotated Region 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 of AnnotationBasedExpiration initialized with default ExpirationAttributes to process expired annotated Region entries using Idle Timeout (TTI) expiration.
    static <K, V> AnnotationBasedExpiration<K,V>
    Factory method used to construct an instance of AnnotationBasedExpiration having no default ExpirationAttributes to process expired annotated Region 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 of AnnotationBasedExpiration initialized with default ExpirationAttributes to process expired annotated Region entries using Time-To-Live (TTL) expiration.
    protected org.springframework.beans.factory.BeanFactory
    Gets a reference to the Spring BeanFactory in which this AnnotationBasedExpiration 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 given Region entry.
    org.apache.geode.cache.ExpirationAttributes
    getExpiry(org.apache.geode.cache.Region.Entry<K,V> entry)
    Calculate the expiration for a given entry.
    getIdleTimeout(org.apache.geode.cache.Region.Entry<K,V> entry)
    Gets the IdleTimeoutExpiration Annotation meta-data from the Region Entry.
    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
    Constructs a new instance of ExpirationAttributes configured with the application domain object specific expiration policy.
    void
    setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
    Sets the BeanFactory managing this AnnotationBasedExpiration 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 of AnnotationBasedExpiration initialized with a specific, default expiration policy.
      Parameters:
      defaultExpirationAttributes - expiration settings used as the default expiration policy.
      See Also:
      • ExpirationAttributes
  • Method Details

    • forIdleTimeout

      public static <K, V> AnnotationBasedExpiration<K,V> forIdleTimeout()
      Factory method used to construct an instance of AnnotationBasedExpiration having no default ExpirationAttributes to process expired annotated Region entries using Idle Timeout (TTI) Expiration.
      Type Parameters:
      K - Class type of the Region entry key.
      V - Class type of the Region entry value.
      Returns:
      an AnnotationBasedExpiration instance to process expired annotated Region 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 of AnnotationBasedExpiration initialized with default ExpirationAttributes to process expired annotated Region entries using Idle Timeout (TTI) expiration.
      Type Parameters:
      K - Class type of the Region entry key.
      V - Class type of the Region entry value.
      Parameters:
      defaultExpirationAttributes - ExpirationAttributes used by default if no expiration policy was specified on the Region.
      Returns:
      an AnnotationBasedExpiration instance to process expired annotated Region entries using Idle Timeout expiration.
      See Also:
    • forTimeToLive

      public static <K, V> AnnotationBasedExpiration<K,V> forTimeToLive()
      Factory method used to construct an instance of AnnotationBasedExpiration having no default ExpirationAttributes to process expired annotated Region entries using Time-To-Live (TTL) Expiration.
      Type Parameters:
      K - Class type of the Region entry key.
      V - Class type of the Region entry value.
      Returns:
      an AnnotationBasedExpiration instance to process expired annotated Region 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 of AnnotationBasedExpiration initialized with default ExpirationAttributes to process expired annotated Region entries using Time-To-Live (TTL) expiration.
      Type Parameters:
      K - Class type of the Region entry key.
      V - Class type of the Region entry value.
      Parameters:
      defaultExpirationAttributes - ExpirationAttributes used by default if no expiration policy was specified on the Region.
      Returns:
      an AnnotationBasedExpiration instance to process expired annotated Region 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 the BeanFactory managing this AnnotationBasedExpiration bean in the Spring context.
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Parameters:
      beanFactory - the Spring BeanFactory to which this bean belongs.
      Throws:
      org.springframework.beans.BeansException - if the BeanFactory reference cannot be initialized.
      See Also:
    • getBeanFactory

      protected org.springframework.beans.factory.BeanFactory getBeanFactory()
      Gets a reference to the Spring BeanFactory in which this AnnotationBasedExpiration bean is managed.
      Returns:
      a reference to the Spring BeanFactory.
      Throws:
      IllegalStateException - if the BeanFactory 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

      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:
    • 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 the Region should be used. The entry parameter should not be used after this method invocation completes.
      Specified by:
      getExpiry in interface org.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:
    • getExpirationMetaData

      protected AnnotationBasedExpiration.ExpirationMetaData getExpirationMetaData(org.apache.geode.cache.Region.Entry<K,V> entry)
      Gets custom expiration (Annotation-based) policy meta-data for the given Region entry.
      Parameters:
      entry - Region entry used as the source of the expiration policy meta-data.
      Returns:
      AnnotationBasedExpiration.ExpirationMetaData extracted from the Region entry or null if the expiration policy meta-data could not be determined from the Region entry.
      See Also:
    • newExpirationAttributes

      protected org.apache.geode.cache.ExpirationAttributes newExpirationAttributes(AnnotationBasedExpiration.ExpirationMetaData expirationMetaData)
      Constructs a new instance of ExpirationAttributes 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 the ExpirationAttributes.
      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

      protected boolean isExpirationConfigured(org.apache.geode.cache.Region.Entry<K,V> entry)
      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:
    • getExpiration

      protected Expiration getExpiration(org.apache.geode.cache.Region.Entry<K,V> entry)
      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:
    • isIdleTimeoutConfigured

      protected boolean isIdleTimeoutConfigured(org.apache.geode.cache.Region.Entry<K,V> entry)
      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:
    • getIdleTimeout

      protected IdleTimeoutExpiration getIdleTimeout(org.apache.geode.cache.Region.Entry<K,V> entry)
      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:
    • isTimeToLiveConfigured

      protected boolean isTimeToLiveConfigured(org.apache.geode.cache.Region.Entry<K,V> entry)
      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:
    • getTimeToLive

      protected TimeToLiveExpiration getTimeToLive(org.apache.geode.cache.Region.Entry<K,V> entry)
      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:
    • 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 interface org.apache.geode.cache.CacheCallback