Record Class FencingToken
java.lang.Object
java.lang.Record
com.loomcache.server.cp.FencingToken
- Record Components:
value- the monotonically increasing token valuelockName- the name of the lock this token is forsessionId- the session ID that acquired this locktimestamp- the timestamp when the token was issued (milliseconds)
public record FencingToken(long value, String lockName, String sessionId, long timestamp)
extends Record
Represents a fencing token used to prevent stale lock holders from accessing resources.
Purpose: Fencing tokens are monotonically increasing values issued with each lock acquisition. A resource holder can use the token to verify they still hold a valid lock.
Token Semantics:
- Each lock acquisition receives a unique token
- Tokens are globally ordered: later tokens have higher values
- A stale lock holder with an old token will be detected when checking against the current token
- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionFencingToken(long value, String lockName, String sessionId, long timestamp) Creates an instance of aFencingTokenrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisNewerThan(FencingToken other) Validates that this token was issued after the given token.booleanisValidFor(String expectedLockName, String expectedSessionId) Validates that this token is current for the given lock name and session.lockName()Returns the value of thelockNamerecord component.Returns the value of thesessionIdrecord component.longReturns the value of thetimestamprecord component.toString()Returns a string representation of this record class.longvalue()Returns the value of thevaluerecord component.
-
Constructor Details
-
Method Details
-
isNewerThan
Validates that this token was issued after the given token.- Parameters:
other- the other token to compare with- Returns:
- true if this token's value is greater than the other token's value
- Throws:
NullPointerException- if other is null
-
isValidFor
Validates that this token is current for the given lock name and session.- Parameters:
expectedLockName- the expected lock nameexpectedSessionId- the expected session ID- Returns:
- true if this token matches the expected lock and session
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
value
-
lockName
-
sessionId
-
timestamp
-