Class InstanceId

java.lang.Object
me.ahoo.cosid.machine.InstanceId

@Immutable public class InstanceId extends Object
Represents a specific deployment instance of a service.

An InstanceId identifies a particular running instance of a service, which may be part of a deployment that provides stable machine IDs (stable=true) or a dynamic instance where machine IDs may change (stable=false).

See Also:
  • Field Details

    • NONE

      public static final InstanceId NONE
      Sentinel value representing no instance.
  • Constructor Details

    • InstanceId

      public InstanceId(String instanceId, boolean stable)
      Creates a new InstanceId.
      Parameters:
      instanceId - the instance identifier string
      stable - whether this instance has a stable identity
  • Method Details

    • isStable

      public boolean isStable()
      Checks if this instance has a stable identity.

      Stable instances (stable=true) are deployed with stable identities (e.g., Kubernetes StatefulSet) and can rely on having consistent machine IDs across restarts.

      Returns:
      true if the instance has a stable identity
    • getInstanceId

      public String getInstanceId()
      Gets the instance identifier string.
      Returns:
      the instance ID
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static InstanceId of(String host, int port, boolean stable)
      Creates an InstanceId from host and port.
      Parameters:
      host - the host address
      port - the port number
      stable - whether this instance has a stable identity
      Returns:
      a new InstanceId
    • of

      public static InstanceId of(String instanceId, boolean stable)
      Creates an InstanceId from an instance ID string.
      Parameters:
      instanceId - the instance identifier
      stable - whether this instance has a stable identity
      Returns:
      a new InstanceId
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object