Java Transaction Xid Check getXidSize(Xid xid)

Here you can find the source of getXidSize(Xid xid)

Description

The byte[]'s in Xid's are known to be 255 or less in length.

License

Open Source License

Declaration

public static int getXidSize(Xid xid) 

Method Source Code

//package com.java2s;
/*-/*  w  ww.  j a  v  a  2  s  .  c o m*/
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002-2010 Oracle.  All rights reserved.
 *
 */

import javax.transaction.xa.Xid;

public class Main {
    public static final int INT_BYTES = 4;

    /**
     * The byte[]'s in Xid's are known to be 255 or less in length.  So instead
     * of using read/writeByteArray(), we can save 6 bytes per record by making
     * the byte[] length be 1 byte instead of 4.
     */
    public static int getXidSize(Xid xid) {
        byte[] gid = xid.getGlobalTransactionId();
        byte[] bqual = xid.getBranchQualifier();
        return INT_BYTES + // FormatId
                1 + // gxid length byte
                1 + // bqual length byte
                (gid == null ? 0 : gid.length) + // gid bytes
                (bqual == null ? 0 : bqual.length); // bqual bytes
    }
}

Related

  1. getRedisKey(String keyPrefix, Xid xid)
  2. sameTransaction(Xid x1, Xid x2)
  3. sameXID(Xid x1, Xid x2)
  4. xidToString(Xid xid, boolean includeBranchQualifier)