Database Reference
In-Depth Information
Next the expiration time and the retention time are defined. The
TimeUnit
class is an often overlooked Java core class that is part of the
java.util.concurrent
package. It provides convenient conversions to
and from different time units. In this case, the base time format is:
long
expirationMillis = -1;
public
Aggregate expire(
long
time,TimeUnit unit) {
expirationMillis =
TimeUnit.
MILLISECONDS
.convert(time, unit);
return this
;
}
public long
expire(
long
time) {
return
expirationMillis == -1 ?
-1 : expirationMillis*(time/expirationMillis);
}
long
resolutionMillis = 1000;
TimeUnit unit = TimeUnit.
SECONDS
;
public
Aggregate resolution(
long
time,TimeUnit unit)
{
resolutionMillis =
TimeUnit.
MILLISECONDS
.convert(time, unit);
this
.unit = unit;
return this
;
}
The quantization functions can take in a millisecond timestamp and return
an appropriately quantized version. Using the formatting strings from the
preceding code, it can also return a time key that is suitable for use in
key-value storage systems:
public
TimeUnit quantizeUnit() {
return
unit; }
public long
quantize(
long
time) {
return
resolutionMillis*(resolutionMillis/time);
}
public long
quantize(
long
time,TimeUnit unit) {
return
quantize(
TimeUnit.
MILLISECONDS
.convert(time, unit));
}
public
String quantizeString(
long
time) {