Class ResourceId
java.lang.Object
dev.getelements.elements.sdk.cluster.id.ResourceId
- All Implemented Interfaces:
HasNodeId
,Serializable
,Comparable<dev.getelements.elements.sdk.cluster.id.HasCompoundId<dev.getelements.elements.sdk.cluster.id.V1CompoundId>>
Represents the globally unique ID for a particular resource. This is currently backed by
an instance of
UUID
, but the string representation should be considered opaque by users
of this type. Though the ResourceId is may be globally represented by a single UUID, for addressment we represent
a ResourceId as a 3-tuple of UUIDs: (InstanceUuid, ApplicationUuid, ResourceUuid), i.e. Resource r is belongs to
Application a on Instance i. The first two elements of the tuple are represented in the code by a NodeId
owned by a ResourceId
object, and the latter element would be held in a direct UUID object by the
ResourceId
object.
For now, a ResourceId
should at all times have exactly both the NodeId and ResourceUuid assigned and
non-null.
By convention, we may represent the ResourceId as a compound Id string, combining the string representation of the
NodeId
with the string representation of the resource UUID, separated by the ID_SEPARATOR. Such a
string will take the form "{instance_uuid}.{app_uuid}+{resource_uuid}".
Created by patricktwohig on 4/11/17.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
asBytes()
Returns the byte[] representation of thisResourceId
asString()
Returns the string representation of thisResourceId
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
dev.getelements.elements.sdk.cluster.id.V1CompoundId
getId()
Returns theInstanceId
.Returns theNodeId
assocaited with thisResourceId
.static int
Returns the number of bytes when aResourceId
is stored as ainvalid reference
byte[]
int
hashCode()
static ResourceId
Creates a new uniqueResourceId
, with a randomNodeId
.static ResourceId
randomResourceIdForNode
(NodeId nodeId) Creates a new uniqueResourceId
, specifying theNodeId
static ResourceId
resourceIdFromByteBuffer
(ByteBuffer byteBufferRepresentation) Parses a newResourceId
from the givenByteBuffer
.static ResourceId
resourceIdFromByteBuffer
(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aResourceId
from the suppliedByteBuffer
and position, ensuring that the buffer's mark, limit, and position are unaffected.static ResourceId
resourceIdFromBytes
(byte[] byteRepresentation) Parses a newResourceId
from the giveninvalid reference
byte[]
static ResourceId
resourceIdFromString
(String stringRepresentation) Parses a newResourceId
from the givenString
.void
toByteBuffer
(ByteBuffer byteBuffer) Writes thisResourceId
to the suppliedByteBuffer
.void
toByteBuffer
(ByteBuffer byteBuffer, int position) Writes thisResourceId
to aByteBuffer
at the supplied position.toString()
static ResourceId
The Java standard valueOf method.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.getelements.elements.sdk.cluster.id.HasNodeId
getOptionalNodeId
-
Method Details
-
asBytes
public byte[] asBytes()Returns the byte[] representation of thisResourceId
- Returns:
- the string representation
-
asString
Returns the string representation of thisResourceId
- Returns:
- the string representation
-
toByteBuffer
Writes thisResourceId
to the suppliedByteBuffer
.- Parameters:
byteBuffer
- theByteBuffer
to receive theResourceId
-
toByteBuffer
Writes thisResourceId
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
Returns theNodeId
assocaited with thisResourceId
. -
getInstanceId
Returns theInstanceId
.- Returns:
- the
InstanceId
assocaited with thisResourceId
-
equals
-
hashCode
public int hashCode() -
toString
-
valueOf
The Java standard valueOf method.- Parameters:
value
- the value- Returns:
- the
ResourceId
-
getSizeInBytes
public static int getSizeInBytes()Returns the number of bytes when aResourceId
is stored as ainvalid reference
byte[]
- Returns:
- the size, in bytes
-
randomResourceId
Creates a new uniqueResourceId
, with a randomNodeId
. Essentially, this creates an anonymousResourceId
that will never match an actual Resource in the cluster. This is useful for making placeholder values to represent "null" in caches or other instances. -
randomResourceIdForNode
Creates a new uniqueResourceId
, specifying theNodeId
-
resourceIdFromString
Parses a newResourceId
from the givenString
. The should be the string representation returned bytasString()
.- Parameters:
stringRepresentation
- theString
representation of theResourceId
fromasString()
.
-
resourceIdFromBytes
Parses a newResourceId
from the giveninvalid reference
byte[]
asBytes()
.- Parameters:
byteRepresentation
- theinvalid reference
byte[]
ResourceId
fromasBytes()
.
-
resourceIdFromByteBuffer
Parses a newResourceId
from the givenByteBuffer
. The should be the string representation returned byasBytes()
.- Parameters:
byteBufferRepresentation
- theByteBuffer
representation of theResourceId
fromasBytes()
.
-
resourceIdFromByteBuffer
public static ResourceId resourceIdFromByteBuffer(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aResourceId
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
ResourceId
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:
-