FileDocCategorySizeDatePackage
CoordinationXid.javaAPI DocExample5910Tue May 29 16:57:16 BST 2007com.sun.xml.ws.tx.at

CoordinationXid

public class CoordinationXid extends Object implements Xid
Manage mapping between WS-Atomic Transaction coordination identifier and Xid.

Create Xid for imported txn. (one flowed in from different vendor) TODO: if root coordinator, try reusing AS txn id (have to export it though)

Allowing setting of

author
jf39279

Fields Summary
private static Map
coordId2Xid
private static Map
xid2CoordId
private final String
coordId
private static Random
random
private static final int
FORMAT_ID
private final byte[]
gtrId
private static final byte[]
BRANCH_QUALIFIER
private String
stringForm
Constructors Summary
private CoordinationXid(String coordinationXid)
Creates a new instance of CoordinationXid representing an imported coordination id.


                    
        
        gtrId = new byte[16];
        random.nextBytes(gtrId);
        coordId = coordinationXid;
    
Methods Summary
public static voidforget(java.lang.String coordId)
Cleanup.

        final Xid removed = remove(coordId);
        if (removed != null) {
            remove(removed);
        }
    
public static javax.transaction.xa.Xidget(java.lang.String coordId)

        return coordId2Xid.get(coordId);
    
public byte[]getBranchQualifier()

        return BRANCH_QUALIFIER;
    
public java.lang.StringgetCoordinationId()

        return coordId;
    
public intgetFormatId()

 //cache

       
        return FORMAT_ID;
    
public byte[]getGlobalTransactionId()

        return gtrId.clone();
    
public static javax.transaction.xa.XidlookupOrCreate(java.lang.String coordId)


          
        Xid result = get(coordId);
        if (result == null) {
            result = new CoordinationXid(coordId);
            coordId2Xid.put(coordId, result);
            xid2CoordId.put(result, coordId);
        }
        return result;
    
private static javax.transaction.xa.Xidremove(java.lang.String coordId)

        return coordId2Xid.remove(coordId);
    
private static java.lang.Stringremove(javax.transaction.xa.Xid coordId)

        return xid2CoordId.remove(coordId);
    
public java.lang.StringtoString()

        // return cache if it exists
        if (stringForm != null){
            return stringForm;
        }

        // Otherwise format the global identifier.
        //char[] buff = new char[gtrId.length*2 + 2/*'[' and ']'*/ + 3/*bqual and ':'*/];
        char[] buff = new char[gtrId.length * 2 + 3/*bqual and ':'*/];
        int pos = 0;
        //buff[pos++] = '[';

        // Convert the global transaction identifier into a string of hex digits.

        final int globalLen = gtrId.length;
        for (int i = 0; i < globalLen; i++) {
            final int currCharHigh = (gtrId[i] & 0xf0) >> 4;
            final int currCharLow = gtrId[i] & 0x0f;
            buff[pos++] = (char) (currCharHigh + (currCharHigh > 9 ? 'A" - 10 : '0"));
            buff[pos++] = (char) (currCharLow + (currCharLow > 9 ? 'A" - 10 : '0"));
        }

        //buff[pos++] = ':';
        buff[pos++] = '_";
        final int currCharHigh = (0 & 0xf0) >> 4;
        final int currCharLow = 0 & 0x0f;
        buff[pos++] = (char) (currCharHigh + (currCharHigh > 9 ? 'A" - 10 : '0"));
        buff[pos++] = (char) (currCharLow + (currCharLow > 9 ? 'A" - 10 : '0"));
        //buff[pos] = ']';

        // Cache the string form of the global identifier.
        stringForm = new String(buff);
        return stringForm;