Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.geronimo.transaction.log;
 
 
Unique id for a transaction. This implementation is backed by a single byte buffer so can do less copying than one backed by several byte buffers for the different components.

Version:
$Rev: 984469 $ $Date: 2010-08-11 18:49:47 +0200 (Wed, 11 Aug 2010) $
 
 public class XidImpl2 implements XidSerializable {
     private static int HEADER_SIZE = 4;
     private static int ACTION_POS = 0;
     private static int GLOBALID_SIZE_POS = 1;
     private static int BRANCHID_SIZE_POS = 2;
     //3 unused
     private static int FORMAT_ID = 0x4765526f;  // Gero
     private static int FORMAT_SIZE = 4;
 
     private static byte[] FORMAT_ID_BYTES = "Gero".getBytes();
 
     private final byte[] buffer = new byte[ +  + . + .];
     private int hash;
     private Object key;

    
Constructor taking a global id (for the main transaction)

Parameters:
globalId the global transaction id
 
     public XidImpl2(byte[] globalId) {
         System.arraycopy(, 0, );
         [] = (byteglobalId.length;
         System.arraycopy(globalId, 0,  + .);
 
         //this.hash = hash(buffer);
         check();
     }
 
     private void check() {
         if ([] > .) {
             throw new IllegalStateException("Global ID too large: " + []);
         }
         if ([] > .) {
             throw new IllegalStateException("Branch ID too large: " + []);
         }
     }

    
Constructor for a branch id

Parameters:
global the xid of the global transaction this branch belongs to
branch the branch id
 
     public XidImpl2(Xid globalbyte[] branch) {
         if (global instanceof XidImpl2) {
             System.arraycopy(((XidImpl2global)., 0, , 0,  +  + .);
         } else {
             System.arraycopy(, 0, );
             byte[] globalId = global.getGlobalTransactionId();
             System.arraycopy(globalId, 0,  + globalId.length);
         }
         [] = (bytebranch.length;
         System.arraycopy(branch, 0,  +  + ..);
         //hash = hash(buffer);
         check();
     }
 
     public XidImpl2(int formatIdbyte[] globalIdbyte[] branch) {
         //todo this is wrong, it ignores formatId supplied.  Maybe this is ok?
         System.arraycopy(, 0, );
         System.arraycopy(globalId, 0,  + globalId.length);
         [] = (bytebranch.length;
         System.arraycopy(branch, 0,  +  + ..);
         //hash = hash(buffer);
         check();
     }
 
     private int hash(byte[] id) {
         int hash = 0;
         for (int i = 0; i < id.lengthi++) {
            hash = (hash * 37) + id[i];
        }
        return hash;
    }
    public int getFormatId() {
        return ;
    }
    public byte[] getGlobalTransactionId() {
        byte[] globalId = new byte[[]];
        System.arraycopy( + globalId, 0, []);
        return globalId;
    }
    public byte[] getBranchQualifier() {
        byte[] branchId = new byte[[]];
        System.arraycopy( +  + .branchId, 0, []);
        return branchId;
    }
    public boolean equals(Object obj) {
        if (obj instanceof XidImpl2 == false) {
            return false;
        }
        XidImpl2 other = (XidImpl2obj;
        return Arrays.equals(other.buffer);
    }
    public int hashCode() {
        if ( == 0) {
             = hash();
        }
        return ;
    }
    public String toString() {
        StringBuffer s = new StringBuffer("[XidImpl2:formatId=Gero,");
        s.append("globalId=");
        for (int i = i <  + .i++) {
            s.append(Integer.toHexString([i]));
        }
        s.append(",branchId=");
        for (int i =  + .i < .i++) {
            s.append(Integer.toHexString([i]));
        }
        s.append("]");
        return s.toString();
    }
    byte[] getBuffer(byte action) {
        [] = action;
        return ;
    }
    public void setKey(Object key) {
        this. = key;
    }
    public Object getKey() {
        return ;
    }
New to GrepCode? Check out our FAQ X