Class NodeId
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>>
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 Summary
Modifier and TypeMethodDescriptionbyte[]asBytes()Represents thisNodeIdas a set of packed-bytes.asString()Returns the compound Id string representation of thisNodeIddefault intcompareTo(dev.getelements.elements.sdk.cluster.id.HasCompoundId<dev.getelements.elements.sdk.cluster.id.V1CompoundId> o) Compares this instance with the other instance.booleanstatic NodeIdforInstanceAndApplication(InstanceId instanceId, ApplicationId applicationId) static NodeIdforMasterNode(InstanceId instanceId) Creats aNodeIdthat is for a master node.dev.getelements.elements.sdk.cluster.id.V1CompoundIdgetId()Returns theInstanceId.static intReturns the number of bytes when aNodeIdis stored as ainvalid reference
byte[]inthashCode()booleanisMaster()Returns true if thisNodeIdrepresents the master node.static NodeIdnodeIdFromByteBuffer(ByteBuffer byteBufferRepresentation) Reads aNodeIdfrom the suppliedByteBuffer.static NodeIdnodeIdFromByteBuffer(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aNodeIdfrom the suppliedByteBufferand position, ensuring that the buffer's mark, limit, and position are unaffected.static NodeIdnodeIdFromBytes(byte[] byteRepresentation) Parses a newNodeIdfrom the given.invalid reference
byte[]static NodeIdnodeIdFromString(String stringRepresentation) static NodeIdGenerates a completely randomNodeId.voidtoByteBuffer(ByteBuffer byteBuffer) Writes thisNodeIdto aByteBufferat the supplied position.voidtoByteBuffer(ByteBuffer byteBuffer, int position) Writes thisNodeIdto aByteBufferat the supplied position.toString()static NodeIdThe Java standard valueOf method.
-
Method Details
-
getApplicationId
- Returns:
- the
UUID
-
getInstanceId
Returns theInstanceId.- Returns:
- the
InstanceIdassocaited with thisNodeId
-
asString
Returns the compound Id string representation of thisNodeId- Returns:
- the string representation
-
asBytes
public byte[] asBytes()Represents thisNodeIdas a set of packed-bytes.- Returns:
- the bytes of this
NodeId.
-
toByteBuffer
Writes thisNodeIdto aByteBufferat the supplied position. TheNodeIdwill be placed atBuffer.position(). The supplied buffer must have at leastgetSizeInBytes()bytes remaining.- Parameters:
byteBuffer- the byteBuffer to receive theNodeId
-
toByteBuffer
Writes thisNodeIdto aByteBufferat the supplied position. As the position is specified, this does not affect the buffer's mark, limit, position.- Parameters:
byteBuffer- the byteBuffer to receive theNodeIdposition- the position at which to write the byte buffer
-
getId
public dev.getelements.elements.sdk.cluster.id.V1CompoundId getId() -
getNodeId
Description copied from interface:HasNodeIdReturns aNodeIdfor this instance, throwing an exception if theNodeIdis not valid. This may return null to indicate that theNodeIdis neither valid nor invalid, but rather simply not present.- Specified by:
getNodeIdin interfaceHasNodeId- Returns:
- the
NodeIdor null. - Throws:
InvalidNodeIdException- if this instance is unable to derive aNodeId
-
getOptionalNodeId
Description copied from interface:HasNodeIdReturn andOptional<NodeId>. If this can't determine the node id, then this must return an empty instance ofOptional. UnlinkeHasNodeId.getNodeId(), this makes no distinction between a missing and an invalid id.- Specified by:
getOptionalNodeIdin interfaceHasNodeId- Returns:
-
equals
-
hashCode
public int hashCode() -
toString
-
getSizeInBytes
public static int getSizeInBytes()Returns the number of bytes when aNodeIdis stored as ainvalid reference
byte[]- Returns:
- the size, in bytes
-
isMaster
public boolean isMaster()Returns true if thisNodeIdrepresents the master node.- Returns:
-
valueOf
The Java standard valueOf method.- Parameters:
value- the value- Returns:
- the
NodeId
-
randomNodeId
Generates a completely randomNodeId. Used mostly for testing.- Returns:
- a newly constructued
NodeId
-
forMasterNode
Creats aNodeIdthat 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
NodeIdfor the instance
-
forInstanceAndApplication
- Parameters:
instanceId- theInstanceIdapplicationId- theApplicationId- Returns:
- a new
NodeId
-
nodeIdFromString
Parses a newNodeIdfrom the givenString. The should be the string representation returned bytasString().- Parameters:
stringRepresentation- theStringrepresentation of theNodeIdfromasString().
-
nodeIdFromBytes
Parses a newNodeIdfrom the given. The should be the string representation returned bytinvalid reference
byte[]asString(). -
nodeIdFromByteBuffer
Reads aNodeIdfrom the suppliedByteBuffer. The buffer's position will be advanced by the size of theNodeId.- Parameters:
byteBufferRepresentation- the byte buffer to read- Returns:
- the
NodeIdinstance
-
nodeIdFromByteBuffer
public static NodeId nodeIdFromByteBuffer(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aNodeIdfrom the suppliedByteBufferand position, ensuring that the buffer's mark, limit, and position are unaffected.- Parameters:
byteBufferRepresentation- the byte buffer to readbyteBufferPosition- the position of the node id within the byte buffer- Returns:
- the
NodeIdinstance
-
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:
compareToin interfaceComparable<CompoundIdT extends Comparable<CompoundIdT>>- Parameters:
o- the instance- Returns:
-