/** * Get the VMID for the current virtual machine. * * @return Virtual machine identifier. * */ public synchronized static VMID getInstance() { if (instance == null) { instance = create(); } return instance; }
/** * Returns a VMID as a string. * * @return VMID as a string. */ public static String asString() { return getInstance().toString(); }
/** * Construct a new GUID. */ public GUID() { this.vmid = VMID.getInstance(); this.uid = new UID(); // generate a hash code for this GUID int code = vmid.hashCode(); code ^= uid.hashCode(); hashCode = code; }
/** * Create the VMID for the current virtual mahcine. * * @return Virtual machine identifer. */ private static VMID create() { // get the local internet address for the current host byte[] address = getHostAddress(); return new VMID(address, PID.getInstance(), new UID()); } }
/** * Return a string representation of this GUID. * * @return A string representation of this GUID. */ public String toString() { // JBCOMMON-88. Cache this as it's expensive to create if (toString == null) { toString = vmid.toString() + "-" + uid.toString(); } return toString; }
/** * Check if the given object is equal to this GUID. * * <p>A GUID is equal to another GUID if the VMID and UID portions are * equal. * * @param obj Object to test equality with. * @return True if object is equal to this GUID. */ public boolean equals(final Object obj) { if (obj == this) return true; if (obj != null && obj.getClass() == getClass()) { GUID guid = (GUID)obj; return guid.vmid.equals(vmid) && guid.uid.equals(uid); } return false; }