@Persistent public final class TimeToLive extends Object implements Serializable
This class is restricted to durations of days and hours. It is only
used as input related to time to live (TTL) for Row
instances,
set by using Row.setTTL(oracle.kv.table.TimeToLive)
. Construction allows only day and hour
durations for efficiency reasons. Durations of days are recommended as they
result in the least amount of storage consumed in a store.
Only positive durations are allowed on input, although negative durations
can be returned from fromExpirationTime(long, long)
if the expirationTime is
in the past relative to the referenceTime.
Modifier and Type | Field and Description |
---|---|
static TimeToLive |
DO_NOT_EXPIRE
A convenience constant that can be used as an argument to
Row.setTTL(oracle.kv.table.TimeToLive) to indicate that the row should not expire. |
Modifier and Type | Method and Description |
---|---|
static TimeUnit |
convertTimeToLiveUnit(int ttlVal,
byte unitOrdinal)
Converts an ordinal value for a TTL TimeUnit into the TimeUnit.
|
boolean |
equals(Object other)
Equality compares the duration only if the units used for construction
are the same.
|
static TimeToLive |
fromExpirationTime(long expirationTime,
long referenceTime)
Returns an instance of TimeToLive based on an absolute expiration
time and a reference time.
|
static TimeUnit |
getTTLUnit(TimeToLive ttl)
Returns the TimeUnit associated with a
TimeToLive , or
{TimeUnit#DAYS} if the ttl is null. |
static int |
getTTLValue(TimeToLive ttl)
Returns the numeric duration value associated with a
TimeToLive ,
or 0 if the ttl is null. |
int |
hashCode() |
static TimeToLive |
ofDays(long days)
Creates a duration using a period of 24 hour days.
|
static TimeToLive |
ofHours(long hours)
Creates a duration using a period of hours.
|
long |
toDays()
Returns the number of days in this duration, which may be negative.
|
long |
toExpirationTime(long referenceTime)
Returns an absolute time representing the duration plus the absolute
time reference parameter.
|
long |
toHours()
Returns the number of hours in this duration, which may be negative.
|
String |
toString() |
static void |
writeFastExternal(DataOutput out,
short serialVersion,
int ttlVal,
TimeUnit ttlUnit)
Writes a TTL value to the output stream.
|
public static final TimeToLive DO_NOT_EXPIRE
Row.setTTL(oracle.kv.table.TimeToLive)
to indicate that the row should not expire.public static TimeToLive ofHours(long hours)
hours
- the number of hours in the duration, must be
a non-negative numberIllegalArgumentException
- if a negative value is providedpublic static TimeToLive ofDays(long days)
days
- the number of days in the duration, must be
a non-negative numberIllegalArgumentException
- if a negative value is providedpublic long toDays()
public long toHours()
public long toExpirationTime(long referenceTime)
System.currentTimeMillis()
. If the
duration of this object is 0 (DO_NOT_EXPIRE
), indicating no
expiration time, this method will return 0, regardless of the reference
time.referenceTime
- an absolute time in milliseconds since January
1, 1970.public static TimeToLive fromExpirationTime(long expirationTime, long referenceTime)
System.currentTimeMillis()
.
If the expirationTime is 0, the referenceTime is ignored and a
TimeToLive of duration 0 is created, indicating no expiration.
Days will be use as the primary unit of duration if the expiration time is evenly divisible into days, otherwise hours are used.
expirationTime
- an absolute time in milliseconds since January
1, 1970referenceTime
- an absolute time in milliseconds since January
1, 1970.public boolean equals(Object other)
public static TimeUnit convertTimeToLiveUnit(int ttlVal, byte unitOrdinal)
public static int getTTLValue(TimeToLive ttl)
TimeToLive
,
or 0 if the ttl is null.ttl
- the ttl or nullpublic static TimeUnit getTTLUnit(TimeToLive ttl)
TimeToLive
, or
{TimeUnit#DAYS} if the ttl is null.ttl
- the ttl or nullpublic static void writeFastExternal(DataOutput out, short serialVersion, int ttlVal, TimeUnit ttlUnit) throws IOException
serialVersion
SerialVersion.TTL_SERIAL_VERSION
and greater:
int
) ttlVal
byte
) ttlUnit
// TimeUnit.DAYS
=6, TimeUnit.HOURS
=5, only present if ttlVal
is not 0
out
- the output streamserialVersion
- the version of the serialization formatttlVal
- the TTL valuettlUnit
- the TTL time unit, may be null if ttVal is 0IOException
Copyright (c) 2011, 2017 Oracle and/or its affiliates. All rights reserved.