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 thisNodeId
as a set of packed-bytes.asString()
Returns the compound Id string representation of thisNodeId
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.boolean
static NodeId
forInstanceAndApplication
(InstanceId instanceId, ApplicationId applicationId) static NodeId
forMasterNode
(InstanceId instanceId) Creats aNodeId
that is for a master node.dev.getelements.elements.sdk.cluster.id.V1CompoundId
getId()
Returns theInstanceId
.static int
Returns the number of bytes when aNodeId
is stored as ainvalid reference
byte[]
int
hashCode()
boolean
isMaster()
Returns true if thisNodeId
represents the master node.static NodeId
nodeIdFromByteBuffer
(ByteBuffer byteBufferRepresentation) Reads aNodeId
from the suppliedByteBuffer
.static NodeId
nodeIdFromByteBuffer
(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aNodeId
from the suppliedByteBuffer
and position, ensuring that the buffer's mark, limit, and position are unaffected.static NodeId
nodeIdFromBytes
(byte[] byteRepresentation) Parses a newNodeId
from the giveninvalid reference
byte[]
static NodeId
nodeIdFromString
(String stringRepresentation) static NodeId
Generates a completely randomNodeId
.void
toByteBuffer
(ByteBuffer byteBuffer) Writes thisNodeId
to aByteBuffer
at the supplied position.void
toByteBuffer
(ByteBuffer byteBuffer, int position) Writes thisNodeId
to aByteBuffer
at the supplied position.toString()
static NodeId
The Java standard valueOf method.
-
Method Details
-
getApplicationId
- Returns:
- the
UUID
-
getInstanceId
Returns theInstanceId
.- Returns:
- the
InstanceId
assocaited with thisNodeId
-
asString
Returns the compound Id string representation of thisNodeId
- Returns:
- the string representation
-
asBytes
public byte[] asBytes()Represents thisNodeId
as a set of packed-bytes.- Returns:
- the bytes of this
NodeId
.
-
toByteBuffer
Writes thisNodeId
to aByteBuffer
at the supplied position. TheNodeId
will be placed atBuffer.position()
. The supplied buffer must have at leastgetSizeInBytes()
bytes remaining.- Parameters:
byteBuffer
- the byteBuffer to receive theNodeId
-
toByteBuffer
Writes thisNodeId
to aByteBuffer
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 theNodeId
position
- the position at which to write the byte buffer
-
getId
public dev.getelements.elements.sdk.cluster.id.V1CompoundId getId() -
getNodeId
Description copied from interface:HasNodeId
Returns aNodeId
for this instance, throwing an exception if theNodeId
is not valid. This may return null to indicate that theNodeId
is neither valid nor invalid, but rather simply not present.- Specified by:
getNodeId
in interfaceHasNodeId
- Returns:
- the
NodeId
or null. - Throws:
InvalidNodeIdException
- if this instance is unable to derive aNodeId
-
getOptionalNodeId
Description copied from interface:HasNodeId
Return 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:
getOptionalNodeId
in interfaceHasNodeId
- Returns:
-
equals
-
hashCode
public int hashCode() -
toString
-
getSizeInBytes
public static int getSizeInBytes()Returns the number of bytes when aNodeId
is stored as ainvalid reference
byte[]
- Returns:
- the size, in bytes
-
isMaster
public boolean isMaster()Returns true if thisNodeId
represents 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 aNodeId
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
- Parameters:
instanceId
- theInstanceId
applicationId
- theApplicationId
- Returns:
- a new
NodeId
-
nodeIdFromString
Parses a newNodeId
from the givenString
. The should be the string representation returned bytasString()
.- Parameters:
stringRepresentation
- theString
representation of theNodeId
fromasString()
.
-
nodeIdFromBytes
Parses a newNodeId
from the giveninvalid reference
byte[]
asString()
. -
nodeIdFromByteBuffer
Reads aNodeId
from the suppliedByteBuffer
. The buffer's position will be advanced by the size of theNodeId
.- Parameters:
byteBufferRepresentation
- the byte buffer to read- Returns:
- the
NodeId
instance
-
nodeIdFromByteBuffer
public static NodeId nodeIdFromByteBuffer(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aNodeId
from the suppliedByteBuffer
and 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
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 interfaceComparable<CompoundIdT extends Comparable<CompoundIdT>>
- Parameters:
o
- the instance- Returns:
-