[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Re: XARecovery - MQ/Messaging merge

mskonda do-not-reply at jboss.com
Tue Sep 5 11:31:47 EDT 2006


TransactionRepositroy.java

public List getPreparedTransactions()
  |    {
  |       ArrayList prepared = new ArrayList();
  |       
  |       log.info("Prepared Transaction in gloabalToLocalMap"+globalToLocalMap);
  |       
  |       Iterator iter = globalToLocalMap.values().iterator();
  |       while (iter.hasNext())
  |       {
  |          Transaction tx = (Transaction)iter.next();
  |          if (tx.xid != null && tx.getState() == Transaction.STATE_PREPARED)
  |          {
  |             prepared.add(tx.getXid());
  |          }
  |       }
  |       return prepared;
  |    }
  |    
  |    /*
  |     * Load any prepared transactions into the repository so they can be recovered
  |     */
  |    public void loadPreparedTransactions() throws Exception
  |    {
  |       List prepared = null;
  |             
  |       prepared = persistenceManager.retrievePreparedTransactions();
  |       
  |       if (prepared != null)
  |       {         
  |          Iterator iter = prepared.iterator();
  |          
  |          while (iter.hasNext())
  |          {
  |         	PreparedTxInfo txInfo = (PreparedTxInfo)iter.next();
  |         	
  |         	Transaction tx = createTransaction(txInfo);            
  |             tx.state = Transaction.STATE_PREPARED;
  |             
  |             // we have to associate a callback to the prepared transaction
  |             // --MK
  |             persistenceManager.associateCallbackToPreparedTx(tx);
  |             
  |             //Load the references for this transaction
  |          }
  |       }
  |    }
  |          
  |    /**
  |     * Creates a prepared transaction 
  |     * @param txInfo
  |     * @return
  |     * @throws Exception
  |     */
  |    private Transaction createTransaction(PreparedTxInfo txInfo) throws Exception {
  | 	   System.out.println("PreparedTxInfo:Xid "+txInfo.getTxId());	   
  | 	   if (globalToLocalMap.containsKey(txInfo.getXid()))
  | 	      {
  | 	         throw new TransactionException("There is already a local tx for global tx " + txInfo.getXid());
  | 	      }	
  | 	      
  |           //Resurrected tx
  | 	      Transaction tx = new Transaction(txInfo.getTxId(), txInfo.getXid());
  | 	      
  | 	      if (trace) { log.trace("created transaction " + tx); }
  | 	      
  | 	      globalToLocalMap.put(txInfo.getXid(), tx);
  | 	      
  | 	      return tx;
  | }
  | 
  | public Transaction getPreparedTx(Xid xid) throws Exception
  |    {
  | 	  // the incoming Xid from Arjuna's RM is funny formatted!
  | 	  // hence we have to do our way
  | 	  // I have to look into this carefully a bit later.
  | 	
  | 	  Xid x = new XidImpl(xid.getBranchQualifier(),xid.getFormatId(), xid.getGlobalTransactionId());
  | 	  
  | 	  Transaction tx = (Transaction)globalToLocalMap.get(x);
  |       if (tx == null)
  |       {
  |          throw new TransactionException("Cannot find local tx for xid:" + xid);
  |       }
  |       if (tx.getState() != Transaction.STATE_PREPARED)
  |       {
  |          throw new TransactionException("Transaction with xid " + xid + " is not in prepared state");
  |       }
  |       return tx;
  |    }
  | 
JDBCPersistenceManager.java
public void associateCallbackToPreparedTx(Transaction tx)
  |    {
  | 	  TransactionCallback callback = (TransactionCallback) tx.getKeyedCallback(this);
  | 
  |       if (callback == null)
  |       {
  |          callback = new TransactionCallback(tx);
  | 
  |          tx.addKeyedCallback(callback, this);
  |       }
  |    }
  |    
  |    public List retrievePreparedTransactions() throws Exception
  |    {
  |       Connection conn = null;
  |       Statement st = null;
  |       ResultSet rs = null;
  |       PreparedTxInfo txInfo = null; 
  |       TransactionWrapper wrap = new TransactionWrapper();
  |       
  |       try
  |       {
  |          List transactions = new ArrayList();
  |          
  |          conn = ds.getConnection();
  |          
  |          st = conn.createStatement();
  |          rs = st.executeQuery(selectPreparedTransactions);
  |          
  |          while (rs.next())
  |          {
  |         	//get the exiting tx id --MK START
  |             long txId = rs.getLong(1);
  |             byte[] branchQual = rs.getBytes(2);
  |             int formatId = rs.getInt(3);
  |             byte[] globalTxId = rs.getBytes(4);
  |             Xid xid = new XidImpl(branchQual, formatId, globalTxId);
  | 
  |             // create a tx info object with the result set detailsdetails
  |             txInfo = new PreparedTxInfo(txId, xid);
  |             transactions.add(txInfo);
  |          }
  |          
  |          return transactions;
  |          
  |       }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969505#3969505

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969505



More information about the jboss-dev-forums mailing list