TimeToLive

class borneo.TimeToLive(value, timeunit)[source]

Bases: object

TimeToLive is a utility class that represents a period of time, similar to java.time.Duration in Java, but specialized to the needs of this driver.

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.

Construction allows only day and hour durations for efficiency reasons. Durations of days are recommended as they result in the least amount of storage overhead. Only positive durations are allowed on input.

Parameters:
  • value (int) – value of time.
  • timeunit (TimeUnit) – unit of time, cannot be None.
Raises:

IllegalArgumentException – raises the exception if parameters are not expected type.

Methods Summary

get_unit() Returns the time unit used for the duration.
get_value() Returns the numeric duration value.
of_days(days) Creates a duration using a period of 24 hour days.
of_hours(hours) Creates a duration using a period of hours.
to_days() Returns the number of days in this duration, which may be negative.
to_expiration_time(reference_time) Returns an absolute time representing the duration plus the absolute time reference parameter.
to_hours() Returns the number of hours in this duration, which may be negative.

Methods Documentation

get_unit()[source]

Returns the time unit used for the duration.

Returns:the timeunit.
Return type:TimeUnit
get_value()[source]

Returns the numeric duration value.

Returns:the duration value, independent of unit.
Return type:int
static of_days(days)[source]

Creates a duration using a period of 24 hour days.

Parameters:days (int) – the number of days in the duration, must be a non-negative number.
Returns:the duration.
Return type:TimeToLive
Raises:IllegalArgumentException – raises the exception if a negative value is provided.
static of_hours(hours)[source]

Creates a duration using a period of hours.

Parameters:hours (int) – the number of hours in the duration, must be a non-negative number.
Returns:the duration.
Return type:TimeToLive
Raises:IllegalArgumentException – raises the exception if a negative value is provided.
to_days()[source]

Returns the number of days in this duration, which may be negative.

Returns:the number of days.
Return type:int
to_expiration_time(reference_time)[source]

Returns an absolute time representing the duration plus the absolute time reference parameter. If an expiration time from the current time is desired the parameter should be the current system time in millisecond. If the duration of this object is 0, indicating no expiration time, this method will return 0, regardless of the reference time.

Parameters:reference_time (int) – an absolute time in milliseconds since January 1, 1970.
Returns:time in milliseconds, 0 if this object’s duration is 0.
Return type:int
Raises:IllegalArgumentException – raises the exception if reference_time is not positive.
to_hours()[source]

Returns the number of hours in this duration, which may be negative.

Returns:the number of hours.
Return type:int