Package com.hazelcast.cache
Class HazelcastExpiryPolicy
- java.lang.Object
-
- com.hazelcast.cache.HazelcastExpiryPolicy
-
- All Implemented Interfaces:
DataSerializable
,IdentifiedDataSerializable
,java.io.Serializable
,javax.cache.expiry.ExpiryPolicy
public class HazelcastExpiryPolicy extends java.lang.Object implements javax.cache.expiry.ExpiryPolicy, IdentifiedDataSerializable, java.io.Serializable
Hazelcast provides overloads of the typical cache operations with a custom
ExpiryPolicy
parameter.
This class provides a custom implementation of anExpiryPolicy
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/deserializeHazelcastExpiryPolicy(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, java.util.concurrent.TimeUnit timeUnit)
Constructs an expiry policy with provided values for creation, access and update as well as aTimeUnit
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 theDuration
class.HazelcastExpiryPolicy(javax.cache.expiry.ExpiryPolicy expiryPolicy)
Copy Constructor for an already existingExpiryPolicy
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.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 streamjava.lang.String
toString()
void
writeData(ObjectDataOutput out)
Writes object fields to output stream
-
-
-
Constructor Detail
-
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 creationaccessMillis
- expiry time in milliseconds after last accessupdateMillis
- expiry time in milliseconds after last update
-
HazelcastExpiryPolicy
public HazelcastExpiryPolicy(long createDurationAmount, long accessDurationAmount, long updateDurationAmount, java.util.concurrent.TimeUnit timeUnit)
Constructs an expiry policy with provided values for creation, access and update as well as aTimeUnit
to convert those values to internally used time unites.- Parameters:
createDurationAmount
- expiry time after creationaccessDurationAmount
- expiry time after last accessupdateDurationAmount
- expiry time after last updatetimeUnit
- time unit of the previous value parameters
-
HazelcastExpiryPolicy
public HazelcastExpiryPolicy(javax.cache.expiry.ExpiryPolicy expiryPolicy)
Copy Constructor for an already existingExpiryPolicy
. 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 theDuration
class.- Parameters:
create
- expiry duration after creationaccess
- expiry duration after last accessupdate
- expiry duration after last update
-
-
Method Detail
-
getExpiryForCreation
public javax.cache.expiry.Duration getExpiryForCreation()
- Specified by:
getExpiryForCreation
in interfacejavax.cache.expiry.ExpiryPolicy
-
getExpiryForAccess
public javax.cache.expiry.Duration getExpiryForAccess()
- Specified by:
getExpiryForAccess
in interfacejavax.cache.expiry.ExpiryPolicy
-
getExpiryForUpdate
public javax.cache.expiry.Duration getExpiryForUpdate()
- Specified by:
getExpiryForUpdate
in interfacejavax.cache.expiry.ExpiryPolicy
-
getFactoryId
public int getFactoryId()
Description copied from interface:IdentifiedDataSerializable
Returns DataSerializableFactory factory ID for this class.- Specified by:
getFactoryId
in interfaceIdentifiedDataSerializable
- 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 interfaceIdentifiedDataSerializable
- Returns:
- type ID
-
writeData
public void writeData(ObjectDataOutput out) throws java.io.IOException
Description copied from interface:DataSerializable
Writes object fields to output stream- Specified by:
writeData
in interfaceDataSerializable
- Parameters:
out
- output- Throws:
java.io.IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the output stream has been closed.
-
readData
public void readData(ObjectDataInput in) throws java.io.IOException
Description copied from interface:DataSerializable
Reads fields from the input stream- Specified by:
readData
in interfaceDataSerializable
- Parameters:
in
- input- Throws:
java.io.IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the input stream has been closed.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-