/*************************************** * * * JBoss: The OpenSource J2EE WebOS * * * * Distributable under LGPL license. * * See terms of license at gnu.org. * * * ***************************************/ package org.jboss.util.id; import java.net.InetAddress; import java.security.AccessController; import java.security.PrivilegedAction; import org.jboss.util.Primitives; import org.jboss.util.HashCode; import org.jboss.util.platform.PID; /** * An object that uniquely identifies a virtual machine. * *
The identifier is composed of: *
* [ address ] - [ process id ] - [ time ] - [ counter ] * |------- UID --------| ** *
Numbers are converted to radix(Character.MAX_RADIX) when converting * to strings. * * @see UID * * @version $Revision: 1.1 $ * @author Jason Dillon */ public class VMID implements ID { /** The address of the current virtual machine */ protected final byte[] address; /** The process identifier of the current virtual machine */ protected final PID pid; /** A unique identifier to ensure uniqueness across the host machine */ protected final UID uid; /** The hash code of this VMID */ protected final int hashCode; /** * Construct a new VMID. * * @param address The address of the current virtual machine. * @param pid Process identifier. * @param uid Unique identifier. * * @see #getInstance() For getting a VMID instance reference. */ protected VMID(final byte[] address, final PID pid, final UID uid) { this.address = address; this.pid = pid; this.uid = uid; // generate a hashCode for this VMID int code = pid.hashCode(); code ^= uid.hashCode(); code ^= HashCode.generate(address); hashCode = code; } /** * Copy a VMID. * * @param vmid VMID to copy. */ protected VMID(final VMID vmid) { this.address = vmid.address; this.pid = vmid.pid; this.uid = vmid.uid; this.hashCode = vmid.hashCode; } /** * Get the address portion of this VMID. * * @return The address portion of this VMID. */ public final byte[] getAddress() { return address; } /** * Get the process identifier portion of this VMID. * * @return The process identifier portion of this VMID. */ public final PID getProcessID() { return pid; } /** * Get the UID portion of this VMID. * * @return The UID portion of this VMID. */ public final UID getUID() { return uid; } /** * Return a string representation of this VMID. * * @return A string representation of this VMID. */ public String toString() { StringBuffer buff = new StringBuffer(); for (int i=0; i