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 thisResourceIdasString()Returns the string representation of thisResourceIddefault intcompareTo(dev.getelements.elements.sdk.cluster.id.HasCompoundId<dev.getelements.elements.sdk.cluster.id.V1CompoundId> o) Compares this instance with the other instance.booleandev.getelements.elements.sdk.cluster.id.V1CompoundIdgetId()Returns theInstanceId.Returns theNodeIdassocaited with thisResourceId.static intReturns the number of bytes when aResourceIdis stored as ainvalid reference
byte[]inthashCode()static ResourceIdCreates a new uniqueResourceId, with a randomNodeId.static ResourceIdrandomResourceIdForNode(NodeId nodeId) Creates a new uniqueResourceId, specifying theNodeIdstatic ResourceIdresourceIdFromByteBuffer(ByteBuffer byteBufferRepresentation) Parses a newResourceIdfrom the givenByteBuffer.static ResourceIdresourceIdFromByteBuffer(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aResourceIdfrom the suppliedByteBufferand position, ensuring that the buffer's mark, limit, and position are unaffected.static ResourceIdresourceIdFromBytes(byte[] byteRepresentation) Parses a newResourceIdfrom the given.invalid reference
byte[]static ResourceIdresourceIdFromString(String stringRepresentation) Parses a newResourceIdfrom the givenString.voidtoByteBuffer(ByteBuffer byteBuffer) Writes thisResourceIdto the suppliedByteBuffer.voidtoByteBuffer(ByteBuffer byteBuffer, int position) Writes thisResourceIdto aByteBufferat the supplied position.toString()static ResourceIdThe Java standard valueOf method.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 thisResourceIdto the suppliedByteBuffer.- Parameters:
byteBuffer- theByteBufferto receive theResourceId
-
toByteBuffer
Writes thisResourceIdto 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
Returns theNodeIdassocaited with thisResourceId. -
getInstanceId
Returns theInstanceId.- Returns:
- the
InstanceIdassocaited 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 aResourceIdis stored as ainvalid reference
byte[]- Returns:
- the size, in bytes
-
randomResourceId
Creates a new uniqueResourceId, with a randomNodeId. Essentially, this creates an anonymousResourceIdthat 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 newResourceIdfrom the givenString. The should be the string representation returned bytasString().- Parameters:
stringRepresentation- theStringrepresentation of theResourceIdfromasString().
-
resourceIdFromBytes
Parses a newResourceIdfrom the given. The should be the string representation returned bytinvalid reference
byte[]asBytes().- Parameters:
byteRepresentation- therepresentation of theinvalid reference
byte[]ResourceIdfromasBytes().
-
resourceIdFromByteBuffer
Parses a newResourceIdfrom the givenByteBuffer. The should be the string representation returned byasBytes().- Parameters:
byteBufferRepresentation- theByteBufferrepresentation of theResourceIdfromasBytes().
-
resourceIdFromByteBuffer
public static ResourceId resourceIdFromByteBuffer(ByteBuffer byteBufferRepresentation, int byteBufferPosition) Reads aResourceIdfrom 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
ResourceIdinstance
-
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:
-