Class HazelcastExpiryPolicy

java.lang.Object
com.hazelcast.cache.HazelcastExpiryPolicy
All Implemented Interfaces:
DataSerializable, IdentifiedDataSerializable, Serializable, javax.cache.expiry.ExpiryPolicy

public class HazelcastExpiryPolicy
extends Object
implements javax.cache.expiry.ExpiryPolicy, IdentifiedDataSerializable, Serializable

Hazelcast provides overloads of the typical cache operations with a custom ExpiryPolicy parameter.
This class provides a custom implementation of an ExpiryPolicy to react on all three types of policies:

  • Create
  • Access
  • Update

Sample usage:

   ICache<Key, Value> unwrappedCache =  cache.unwrap( ICache.class );
   HazelcastExpiryPolicy customExpiry = new HazelcastExpiryPolicy(20, 30, 40, TimeUnit.SECONDS);
   unwrappedCache.put("key1", value, customExpiry );
 
Since:
3.3.1
See Also:
Serialized Form
  • Constructor Summary

    Constructors
    Constructor Description
    HazelcastExpiryPolicy()
    Default constructor to serialize/deserialize
    HazelcastExpiryPolicy​(long createMillis, long accessMillis, long updateMillis)
    Constructs an expiry policy with provided values for creation, access and update in milliseconds.
    HazelcastExpiryPolicy​(long createDurationAmount, long accessDurationAmount, long updateDurationAmount, TimeUnit timeUnit)
    Constructs an expiry policy with provided values for creation, access and update as well as a TimeUnit to convert those values to internally used time unites.
    HazelcastExpiryPolicy​(javax.cache.expiry.Duration create, javax.cache.expiry.Duration access, javax.cache.expiry.Duration update)
    Constructs an expiry policy with provided values for creation, access and update by providing instances of the Duration class.
    HazelcastExpiryPolicy​(javax.cache.expiry.ExpiryPolicy expiryPolicy)
    Copy Constructor for an already existing ExpiryPolicy.
  • Method Summary

    Modifier and Type Method Description
    boolean equals​(Object o)  
    int getClassId()
    Returns type identifier for this class.
    javax.cache.expiry.Duration getExpiryForAccess()  
    javax.cache.expiry.Duration getExpiryForCreation()  
    javax.cache.expiry.Duration getExpiryForUpdate()  
    int getFactoryId()
    Returns DataSerializableFactory factory ID for this class.
    int hashCode()  
    void readData​(ObjectDataInput in)
    Reads fields from the input stream
    String toString()  
    void writeData​(ObjectDataOutput out)
    Writes object fields to output stream

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • HazelcastExpiryPolicy

      public HazelcastExpiryPolicy()
      Default constructor to serialize/deserialize
    • HazelcastExpiryPolicy

      public HazelcastExpiryPolicy​(long createMillis, long accessMillis, long updateMillis)
      Constructs an expiry policy with provided values for creation, access and update in milliseconds.
      Parameters:
      createMillis - expiry time in milliseconds after creation
      accessMillis - expiry time in milliseconds after last access
      updateMillis - expiry time in milliseconds after last update
    • HazelcastExpiryPolicy

      public HazelcastExpiryPolicy​(long createDurationAmount, long accessDurationAmount, long updateDurationAmount, TimeUnit timeUnit)
      Constructs an expiry policy with provided values for creation, access and update as well as a TimeUnit to convert those values to internally used time unites.
      Parameters:
      createDurationAmount - expiry time after creation
      accessDurationAmount - expiry time after last access
      updateDurationAmount - expiry time after last update
      timeUnit - time unit of the previous value parameters
    • HazelcastExpiryPolicy

      public HazelcastExpiryPolicy​(javax.cache.expiry.ExpiryPolicy expiryPolicy)
      Copy Constructor for an already existing ExpiryPolicy. Values are copied to the internal state as is.
      Parameters:
      expiryPolicy - expiry policy to copy
    • HazelcastExpiryPolicy

      public HazelcastExpiryPolicy​(javax.cache.expiry.Duration create, javax.cache.expiry.Duration access, javax.cache.expiry.Duration update)
      Constructs an expiry policy with provided values for creation, access and update by providing instances of the Duration class.
      Parameters:
      create - expiry duration after creation
      access - expiry duration after last access
      update - expiry duration after last update
  • Method Details

    • getExpiryForCreation

      public javax.cache.expiry.Duration getExpiryForCreation()
      Specified by:
      getExpiryForCreation in interface javax.cache.expiry.ExpiryPolicy
    • getExpiryForAccess

      public javax.cache.expiry.Duration getExpiryForAccess()
      Specified by:
      getExpiryForAccess in interface javax.cache.expiry.ExpiryPolicy
    • getExpiryForUpdate

      public javax.cache.expiry.Duration getExpiryForUpdate()
      Specified by:
      getExpiryForUpdate in interface javax.cache.expiry.ExpiryPolicy
    • getFactoryId

      public int getFactoryId()
      Description copied from interface: IdentifiedDataSerializable
      Returns DataSerializableFactory factory ID for this class.
      Specified by:
      getFactoryId in interface IdentifiedDataSerializable
      Returns:
      factory ID
    • getClassId

      public int getClassId()
      Description copied from interface: IdentifiedDataSerializable
      Returns type identifier for this class. It should be unique per DataSerializableFactory.
      Specified by:
      getClassId in interface IdentifiedDataSerializable
      Returns:
      type ID
    • writeData

      public void writeData​(ObjectDataOutput out) throws IOException
      Description copied from interface: DataSerializable
      Writes object fields to output stream
      Specified by:
      writeData in interface DataSerializable
      Parameters:
      out - output
      Throws:
      IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
    • readData

      public void readData​(ObjectDataInput in) throws IOException
      Description copied from interface: DataSerializable
      Reads fields from the input stream
      Specified by:
      readData in interface DataSerializable
      Parameters:
      in - input
      Throws:
      IOException - if an I/O error occurs. In particular, an IOException may be thrown if the input stream has been closed.
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object