java.lang.Object
dev.getelements.elements.sdk.cluster.id.NodeId
All Implemented Interfaces:
HasNodeId, Serializable, Comparable<dev.getelements.elements.sdk.cluster.id.HasCompoundId<dev.getelements.elements.sdk.cluster.id.V1CompoundId>>

public class NodeId extends Object implements Serializable, HasNodeId
Represents a single worker in the deployment cluster, i.e. the globally-unique identifier for a given game/app processor within a Java process. It is identified by a UUID pair (InstanceUuid, ApplicationUuid), where InstanceUuid is the unique identifier for the ec2 instance, and ApplicationUuid is the application-specific id for the game/app. E.g. if we have three games/apps represented by UUIDs A1, A2, A3, and the workload necessitates horizontal scaling across two ec2 instances represented by UUIDs I1, I2, then we will have six workers in the deployment addressable with the pairs (I1, A1), (I1, A2), (I1, A3), (I2, A1), (I2, A2), (I2, A3).
See Also:
  • Method Details

    • getApplicationId

      public ApplicationId getApplicationId()
      Gets the UUID for this NodeId.
      Returns:
      the UUID
    • getInstanceId

      public InstanceId getInstanceId()
      Returns the InstanceId.
      Returns:
      the InstanceId assocaited with this NodeId
    • asString

      public String asString()
      Returns the compound Id string representation of this NodeId
      Returns:
      the string representation
    • asBytes

      public byte[] asBytes()
      Represents this NodeId as a set of packed-bytes.
      Returns:
      the bytes of this NodeId.
    • toByteBuffer

      public void toByteBuffer(ByteBuffer byteBuffer)
      Writes this NodeId to a ByteBuffer at the supplied position. The NodeId will be placed at Buffer.position(). The supplied buffer must have at least getSizeInBytes() bytes remaining.
      Parameters:
      byteBuffer - the byteBuffer to receive the NodeId
    • toByteBuffer

      public void toByteBuffer(ByteBuffer byteBuffer, int position)
      Writes this NodeId to a ByteBuffer at the supplied position. As the position is specified, this does not affect the buffer's mark, limit, position.
      Parameters:
      byteBuffer - the byteBuffer to receive the NodeId
      position - the position at which to write the byte buffer
    • getId

      public dev.getelements.elements.sdk.cluster.id.V1CompoundId getId()
    • getNodeId

      public NodeId getNodeId() throws InvalidNodeIdException
      Description copied from interface: HasNodeId
      Returns a NodeId for this instance, throwing an exception if the NodeId is not valid. This may return null to indicate that the NodeId is neither valid nor invalid, but rather simply not present.
      Specified by:
      getNodeId in interface HasNodeId
      Returns:
      the NodeId or null.
      Throws:
      InvalidNodeIdException - if this instance is unable to derive a NodeId
    • getOptionalNodeId

      public Optional<NodeId> getOptionalNodeId()
      Description copied from interface: HasNodeId
      Return and Optional<NodeId>. If this can't determine the node id, then this must return an empty instance of Optional. Unlinke HasNodeId.getNodeId(), this makes no distinction between a missing and an invalid id.
      Specified by:
      getOptionalNodeId in interface HasNodeId
      Returns:
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

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

      public static int getSizeInBytes()
      Returns the number of bytes when a NodeId is stored as a
      invalid reference
      byte[]
      Returns:
      the size, in bytes
    • isMaster

      public boolean isMaster()
      Returns true if this NodeId represents the master node.
      Returns:
    • valueOf

      public static NodeId valueOf(String value)
      The Java standard valueOf method.
      Parameters:
      value - the value
      Returns:
      the NodeId
    • randomNodeId

      public static NodeId randomNodeId()
      Generates a completely random NodeId. Used mostly for testing.
      Returns:
      a newly constructued NodeId
    • forMasterNode

      public static NodeId forMasterNode(InstanceId instanceId)
      Creats a NodeId that is for a master node. By convention, the master node is the node whose instance id matches the application ID. This makes it possible to get information about the rest of the hosted nodes by only knowing the instance ID.
      Parameters:
      instanceId - the instance ID.
      Returns:
      the NodeId for the instance
    • forInstanceAndApplication

      public static NodeId forInstanceAndApplication(InstanceId instanceId, ApplicationId applicationId)
      Constructs a NodeId for the given InstanceId as well as ApplicationId.
      Parameters:
      instanceId - the InstanceId
      applicationId - the ApplicationId
      Returns:
      a new NodeId
    • nodeIdFromString

      public static NodeId nodeIdFromString(String stringRepresentation)
      Parses a new NodeId from the given String. The should be the string representation returned byt asString().
      Parameters:
      stringRepresentation - the String representation of the NodeId from asString().
    • nodeIdFromBytes

      public static NodeId nodeIdFromBytes(byte[] byteRepresentation)
      Parses a new NodeId from the given
      invalid reference
      byte[]
      . The should be the string representation returned byt asString().
      Parameters:
      byteRepresentation - the
      invalid reference
      byte[]
      representation of the NodeId from asBytes().
    • nodeIdFromByteBuffer

      public static NodeId nodeIdFromByteBuffer(ByteBuffer byteBufferRepresentation)
      Reads a NodeId from the supplied ByteBuffer. The buffer's position will be advanced by the size of the NodeId.
      Parameters:
      byteBufferRepresentation - the byte buffer to read
      Returns:
      the NodeId instance
    • nodeIdFromByteBuffer

      public static NodeId nodeIdFromByteBuffer(ByteBuffer byteBufferRepresentation, int byteBufferPosition)
      Reads a NodeId from the supplied ByteBuffer and position, ensuring that the buffer's mark, limit, and position are unaffected.
      Parameters:
      byteBufferRepresentation - the byte buffer to read
      byteBufferPosition - the position of the node id within the byte buffer
      Returns:
      the NodeId instance
    • compareTo

      default int compareTo(dev.getelements.elements.sdk.cluster.id.HasCompoundId<dev.getelements.elements.sdk.cluster.id.V1CompoundId> o)
      Compares this instance with the other instance.
      Specified by:
      compareTo in interface Comparable<CompoundIdT extends Comparable<CompoundIdT>>
      Parameters:
      o - the instance
      Returns: