org.apache.cassandra.db

## Class LivenessInfo

- java.lang.Object
- - org.apache.cassandra.db.LivenessInfo

    public class LivenessInfo
    extends java.lang.Object

Stores the information relating to the liveness of the primary key columns of a row.

A `LivenessInfo` can first be empty. If it isn't, it contains at least a timestamp, which is the timestamp for the row primary key columns. On top of that, the info can be ttl'ed, in which case the `LivenessInfo` also has both a ttl and a local expiration time.

Please note that if a liveness info is ttl'ed, that expiration is only an expiration of the liveness info itself (so, of the timestamp), and once the info expires it becomes `EMPTY`. But if a row has a liveness info which expires, the rest of the row data is unaffected (of course, the rest of said row data might be ttl'ed on its own but this is separate).

### Field Summary

Fields
`static LivenessInfo` `EMPTY`
`static int` `EXPIRED_LIVENESS_TTL` Used as flag for representing an expired liveness.
`static int` `NO_EXPIRATION_TIME`
`static long` `NO_TIMESTAMP`
`static int` `NO_TTL`
`protected long` `timestamp`

### Constructor Summary

Constructors
`protected` `LivenessInfo(long timestamp)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static LivenessInfo` `create(long timestamp, int nowInSec)`
`static LivenessInfo` `create(long timestamp, int ttl, int nowInSec)`
`int` `dataSize()` The size of the (useful) data this liveness information contains.
`void` `digest(java.security.MessageDigest digest)` Adds this liveness information to the provided digest.
`boolean` `equals(java.lang.Object other)`
`static LivenessInfo` `expiring(long timestamp, int ttl, int nowInSec)`
`int` `hashCode()`
`boolean` `isEmpty()` Whether this liveness info is empty (has no timestamp).
`protected boolean` `isExpired()`
`boolean` `isExpiring()` Whether the info has a ttl.
`boolean` `isLive(int nowInSec)` Whether that info is still live.
`int` `localExpirationTime()` The expiration time (in seconds) if the info is expiring (`NO_EXPIRATION_TIME` otherwise).
`boolean` `supersedes(LivenessInfo other)` Whether this liveness information supersedes another one (that is whether is has a greater timestamp than the other or not).
`long` `timestamp()` The timestamp for this liveness info.
`java.lang.String` `toString()`
`int` `ttl()` The ttl (if any) on the row primary key columns or `NO_TTL` if it is not expiring.
`void` `validate()` Validate the data contained by this liveness information.
`static LivenessInfo` `withExpirationTime(long timestamp, int ttl, int localExpirationTime)`
`LivenessInfo` `withUpdatedTimestamp(long newTimestamp)` Returns a copy of this liveness info updated with the provided timestamp.
`LivenessInfo` `withUpdatedTimestampAndLocalDeletionTime(long newTimestamp, int newLocalDeletionTime)`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### NO_TIMESTAMP

    public static final long NO_TIMESTAMP

See Also:
  Constant Field Values

#### NO_TTL

    public static final int NO_TTL

See Also:
  Constant Field Values

#### EXPIRED_LIVENESS_TTL

    public static final int EXPIRED_LIVENESS_TTL

Used as flag for representing an expired liveness. TTL per request is at most 20 yrs, so this shouldn't conflict (See `Attributes.MAX_TTL`)

See Also:
  Constant Field Values

#### NO_EXPIRATION_TIME

    public static final int NO_EXPIRATION_TIME

See Also:
  Constant Field Values

#### EMPTY

    public static final LivenessInfo EMPTY

#### timestamp

    protected final long timestamp

### Constructor Detail

#### LivenessInfo

    protected LivenessInfo(long timestamp)

### Method Detail

#### create

    public static LivenessInfo create(long timestamp,
                                      int nowInSec)

#### expiring

    public static LivenessInfo expiring(long timestamp,
                                        int ttl,
                                        int nowInSec)

#### create

    public static LivenessInfo create(long timestamp,
                                      int ttl,
                                      int nowInSec)

#### withExpirationTime

    public static LivenessInfo withExpirationTime(long timestamp,
                                                  int ttl,
                                                  int localExpirationTime)

#### isEmpty

    public boolean isEmpty()

Whether this liveness info is empty (has no timestamp).

Returns:
  whether this liveness info is empty or not.

#### timestamp

    public long timestamp()

The timestamp for this liveness info.

Returns:
  the liveness info timestamp (or `NO_TIMESTAMP` if the info is empty).

#### isExpiring

    public boolean isExpiring()

Whether the info has a ttl.

#### ttl

    public int ttl()

The ttl (if any) on the row primary key columns or `NO_TTL` if it is not expiring. Please note that this value is the TTL that was set originally and is thus not changing.

#### localExpirationTime

    public int localExpirationTime()

The expiration time (in seconds) if the info is expiring (`NO_EXPIRATION_TIME` otherwise).

#### isLive

    public boolean isLive(int nowInSec)

Whether that info is still live. A `LivenessInfo` is live if it is either not expiring, or if its expiration time if after `nowInSec`.

Parameters:
  `nowInSec` - the current time in seconds.
Returns:
  whether this liveness info is live or not.

#### digest

    public void digest(java.security.MessageDigest digest)

Adds this liveness information to the provided digest.

Parameters:
  `digest` - the digest to add this liveness information to.

#### validate

    public void validate()

Validate the data contained by this liveness information.

Throws:
  `MarshalException` - if some of the data is corrupted.

#### dataSize

    public int dataSize()

The size of the (useful) data this liveness information contains.

Returns:
  the size of the data this liveness information contains.

#### supersedes

    public boolean supersedes(LivenessInfo other)

Whether this liveness information supersedes another one (that is whether is has a greater timestamp than the other or not). If timestamps are the same and none of them are expired livenessInfo, livenessInfo with greater TTL supersedes another. It also means, if timestamps are the same, ttl superseders no-ttl. This is the same rule as `Conflicts.resolveRegular(long, boolean, int, java.nio.ByteBuffer, long, boolean, int, java.nio.ByteBuffer)` If timestamps are the same and one of them is expired livenessInfo. Expired livenessInfo supersedes, ie. tombstone supersedes. If timestamps are the same and both of them are expired livenessInfo(Ideally it shouldn't happen), greater localDeletionTime wins.

Parameters:
  `other` - the `LivenessInfo` to compare this info to.
Returns:
  whether this `LivenessInfo` supersedes `other`.

#### isExpired

    protected boolean isExpired()

#### withUpdatedTimestamp

    public LivenessInfo withUpdatedTimestamp(long newTimestamp)

Returns a copy of this liveness info updated with the provided timestamp.

Parameters:
  `newTimestamp` - the timestamp for the returned info.
Returns:
  if this liveness info has a timestamp, a copy of it with `newTimestamp` as timestamp. If it has no timestamp however, this liveness info is returned unchanged.

#### withUpdatedTimestampAndLocalDeletionTime

    public LivenessInfo withUpdatedTimestampAndLocalDeletionTime(long newTimestamp,
                                                                 int newLocalDeletionTime)

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`

#### equals

    public boolean equals(java.lang.Object other)

Overrides:
  `equals` in class `java.lang.Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `java.lang.Object`