bitronix.tm.utils
Class UidGenerator

java.lang.Object
  extended bybitronix.tm.utils.UidGenerator

public class UidGenerator
extends java.lang.Object

Helper that offers UID generation (GTRID, XID, sequences) needed by the transaction manager.

Generated UIDs are at most 64 bytes long and are made of 3 subparts: the current time in milliseconds since Epoch, a JVM transient atomic sequence number and the configured bitronix.tm.serverId.

The reliance on the system clock is critical to the uniqueness of the UID in the network so you have to make sure all servers of the network running this transaction manager have their clock reasonably in sync. An order of 1 second synchronicity is generally fine.

© Bitronix Software

Author:
lorban

Constructor Summary
UidGenerator()
           
 
Method Summary
static Uid generateUid()
          Generate a UID, globally unique.
static BitronixXid generateXid(Uid gtrid)
          Generate a XID with the specified globalTransactionId.
static int getNextSequenceNumber()
          Atomically generate general-purpose sequence numbers starting at 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UidGenerator

public UidGenerator()
Method Detail

generateUid

public static Uid generateUid()
Generate a UID, globally unique. This method relies on the configured serverId for network uniqueness.

Returns:
the generated UID.

getNextSequenceNumber

public static int getNextSequenceNumber()
Atomically generate general-purpose sequence numbers starting at 0. The counter is reset at every JVM startup.

Returns:
a sequence number unique for the lifespan of this JVM.

generateXid

public static BitronixXid generateXid(Uid gtrid)
Generate a XID with the specified globalTransactionId.

Parameters:
gtrid - the GTRID to use to generate the Xid.
Returns:
the generated Xid.