Record Class FencingToken

java.lang.Object
java.lang.Record
com.loomcache.server.cp.FencingToken
Record Components:
value - the monotonically increasing token value
lockName - the name of the lock this token is for
sessionId - the session ID that acquired this lock
timestamp - 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 Details

    • FencingToken

      public FencingToken(long value, String lockName, String sessionId, long timestamp)
      Creates an instance of a FencingToken record class.
      Parameters:
      value - the value for the value record component
      lockName - the value for the lockName record component
      sessionId - the value for the sessionId record component
      timestamp - the value for the timestamp record component
  • Method Details

    • isNewerThan

      public boolean isNewerThan(FencingToken other)
      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

      public boolean isValidFor(String expectedLockName, String expectedSessionId)
      Validates that this token is current for the given lock name and session.
      Parameters:
      expectedLockName - the expected lock name
      expectedSessionId - the expected session ID
      Returns:
      true if this token matches the expected lock and session
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • value

      public long value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component
    • lockName

      public String lockName()
      Returns the value of the lockName record component.
      Returns:
      the value of the lockName record component
    • sessionId

      public String sessionId()
      Returns the value of the sessionId record component.
      Returns:
      the value of the sessionId record component
    • timestamp

      public long timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component