Record Class TopologyInfo

java.lang.Object
java.lang.Record
com.loomcache.server.cluster.TopologyInfo
Record Components:
nodeId - unique node identifier (e.g., "node-1")
rack - rack identifier (e.g., "rack-a")
zone - zone identifier (e.g., "zone-1")
region - region identifier (e.g., "us-west-2")

public record TopologyInfo(String nodeId, String rack, String zone, String region) extends Record
Represents the physical topology location of a node in a distributed cluster.

Topology hierarchy (from most specific to most general):

  • Node ID: unique identifier for this node
  • Rack: physical or logical grouping (e.g., same power supply, network switch)
  • Zone: availability zone or data center section
  • Region: geographic region or data center

Distance calculation:

  • 0: same node
  • 1: different node, same rack
  • 2: different rack, same zone
  • 3: different zone, same region
  • 4: different region
Since:
1.0
  • Constructor Details

    • TopologyInfo

      public TopologyInfo(String nodeId, String rack, String zone, String region)
      Creates an instance of a TopologyInfo record class.
      Parameters:
      nodeId - the value for the nodeId record component
      rack - the value for the rack record component
      zone - the value for the zone record component
      region - the value for the region record component
  • Method Details

    • distance

      public int distance(TopologyInfo other)
      Calculate the distance to another topology location.

      Distance represents network proximity and failure correlation:

      • 0: same node
      • 1: same rack (different node)
      • 2: same zone, different rack
      • 3: same region, different zone
      • 4: different region
      Parameters:
      other - the other topology location
      Returns:
      distance (0-4)
      Throws:
      IllegalArgumentException - if other is null
    • sameRack

      public boolean sameRack(TopologyInfo other)
      Check if this topology is in the same rack as another.
      Parameters:
      other - the other topology location
      Returns:
      true if both are in the same rack
    • sameZone

      public boolean sameZone(TopologyInfo other)
      Check if this topology is in the same zone as another.
      Parameters:
      other - the other topology location
      Returns:
      true if both are in the same zone
    • sameRegion

      public boolean sameRegion(TopologyInfo other)
      Check if this topology is in the same region as another.
      Parameters:
      other - the other topology location
      Returns:
      true if both are in the same region
    • toString

      public final 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • nodeId

      public String nodeId()
      Returns the value of the nodeId record component.
      Returns:
      the value of the nodeId record component
    • rack

      public String rack()
      Returns the value of the rack record component.
      Returns:
      the value of the rack record component
    • zone

      public String zone()
      Returns the value of the zone record component.
      Returns:
      the value of the zone record component
    • region

      public String region()
      Returns the value of the region record component.
      Returns:
      the value of the region record component