Search in sources :

Example 6 with TransactionBroker

use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.

the class TransactionInfo method readExternal.

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    type = in.readInt();
    state = (TransactionState) in.readObject();
    txnHomeBroker = (BrokerAddress) in.readObject();
    txnBkrs = (TransactionBroker[]) in.readObject();
    bkrMap = new HashMap();
    // fix for CR 6858156
    if (txnBkrs != null) {
        for (int i = 0; i < txnBkrs.length; i++) {
            TransactionBroker txnBkr = txnBkrs[i];
            bkrMap.put(txnBkr.getBrokerAddress(), txnBkr);
        }
        // Verify that there are no duplicate
        if (bkrMap.size() != txnBkrs.length) {
            Globals.getLogger().log(Logger.WARNING, "Internal Error: duplicate TransactionBroker object found");
        }
    }
}
Also used : HashMap(java.util.HashMap) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker)

Example 7 with TransactionBroker

use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.

the class TransactionDAOImpl method getTransactionBrokers.

/**
 * Get transaction's participant brokers for the specified transaction..
 *
 * @param conn database connection
 * @param txnUID the transaction ID
 * @return an array of TransactionBroker object
 */
@Override
public TransactionBroker[] getTransactionBrokers(Connection conn, TransactionUID txnUID) throws BrokerException {
    TransactionBroker[] txnBrokers = null;
    long id = txnUID.longValue();
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectTxnBrokersSQL);
        pstmt.setLong(1, id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            txnBrokers = (TransactionBroker[]) Util.readObject(rs, 1);
        } else {
            throw new BrokerException(br.getKString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, String.valueOf(id)), Status.NOT_FOUND);
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + selectTxnBrokersSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        BrokerException be = new BrokerException(br.getKString(BrokerResources.X_LOAD_TRANSACTION_FAILED, txnUID), ex);
        be.setSQLRecoverable(true);
        throw be;
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return txnBrokers;
}
Also used : TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) IOException(java.io.IOException)

Example 8 with TransactionBroker

use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.

the class TransactionDAOImpl method getTransactionInfo.

/**
 * Get the TransactionInfo object.
 *
 * @param conn database connection
 * @param txnUID the transaction ID
 * @return TransactionInfo object
 */
@Override
public TransactionInfo getTransactionInfo(Connection conn, TransactionUID txnUID) throws BrokerException {
    TransactionInfo txnInfo = null;
    long id = txnUID.longValue();
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectTxnInfoSQL);
        pstmt.setLong(1, id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            int type = rs.getInt(1);
            int state = rs.getInt(2);
            TransactionState txnState = (TransactionState) Util.readObject(rs, 3);
            // update state in TransactionState object
            txnState.setState(state);
            BrokerAddress txnHomeBroker = (BrokerAddress) Util.readObject(rs, 4);
            TransactionBroker[] txnBrokers = (TransactionBroker[]) Util.readObject(rs, 5);
            txnInfo = new TransactionInfo(txnState, txnHomeBroker, txnBrokers, type);
        } else {
            throw new BrokerException(br.getKString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, String.valueOf(id)), Status.NOT_FOUND);
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + selectTxnInfoSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        BrokerException be = new BrokerException(br.getKString(BrokerResources.X_LOAD_TRANSACTION_FAILED, txnUID), ex);
        be.setSQLRecoverable(true);
        throw be;
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return txnInfo;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) IOException(java.io.IOException) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)

Example 9 with TransactionBroker

use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.

the class RaptorProtocol method sendClusterTransactionInfo.

// Caller must ensure this is the transaction home broker
private void sendClusterTransactionInfo(TransactionUID tid, BrokerAddress to, Long xid) {
    TransactionList tl = null;
    TransactionState ts = null;
    Object[] oo = TransactionList.getTransListAndState(tid, null, true, false);
    if (oo != null) {
        tl = (TransactionList) oo[0];
        ts = (TransactionState) oo[1];
    }
    BrokerAddress[] parties = null;
    BrokerAddress[] waitfor = null;
    TransactionBroker[] brokers = null;
    if (ts != null) {
        try {
            brokers = tl.getClusterTransactionBrokers(tid);
        } catch (Exception e) {
            logger.log(logger.WARNING, "Can't retrieve cluster transaction brokers:" + e.getMessage());
        }
        if (brokers == null) {
            logger.log(logger.WARNING, "No cluster transaction brokers information for TID=" + tid);
        } else {
            parties = new BrokerAddress[brokers.length];
            ArrayList waits = new ArrayList();
            for (int i = 0; i < brokers.length; i++) {
                parties[i] = brokers[i].getBrokerAddress();
                if (!brokers[i].isCompleted()) {
                    waits.add(brokers[i].getBrokerAddress());
                }
            }
            if (waits.size() > 0) {
                waitfor = (BrokerAddress[]) waits.toArray(new BrokerAddress[waits.size()]);
            }
        }
    }
    UID tranpid = null;
    if (tl != null && Globals.getDestinationList().isPartitionMode()) {
        tranpid = tl.getPartitionedStore().getPartitionID();
    }
    ClusterTxnInfoInfo ii = ClusterTxnInfoInfo.newInstance(Long.valueOf(tid.longValue()), (ts == null ? TransactionState.NULL : ts.getState()), parties, waitfor, Globals.getMyAddress(), true, tranpid, c, xid);
    if (DEBUG_CLUSTER_TXN) {
        logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_SEND_CLUSTER_TXN_INFO, to.toString(), ii.toString()));
    }
    try {
        c.unicast(to, ii.getGPacket());
    } catch (Exception e) {
        String[] args = { ii.toString(), to.toString(), e.getMessage() };
        logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_SEND_CLUSTER_TXN_INFO_FAIL, args));
    }
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) HandshakeInProgressException(com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker)

Example 10 with TransactionBroker

use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.

the class ClusterTransactionManager method updateTransactionBrokerState.

boolean updateTransactionBrokerState(TransactionBroker txnBkr, ClusterTransaction clusterTxn) {
    TransactionBroker[] txnBrokers = clusterTxn.getTransactionBrokers();
    TransactionBroker result = null;
    BrokerAddress b = txnBkr.getBrokerAddress();
    boolean allComplete = true;
    for (int i = 0; i < txnBrokers.length; i++) {
        BrokerAddress ba = txnBrokers[i].getCurrentBrokerAddress();
        if (ba == null) {
            continue;
        }
        if (ba.equals(b)) {
            result = txnBrokers[i];
        } else {
            allComplete &= txnBrokers[i].isCompleted();
        }
    }
    result.setCompleted(true);
    return allComplete;
}
Also used : TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress)

Aggregations

TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)26 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)10 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)9 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)8 IOException (java.io.IOException)8 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)7 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)6 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)6 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)6 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)5 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)4 TransactionAcknowledgement (com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement)4 HandshakeInProgressException (com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException)4 TransactionInfo (com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)4 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)4 UID (com.sun.messaging.jmq.util.UID)4 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)4 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)3 BrokerDownException (com.sun.messaging.jmq.jmsserver.util.BrokerDownException)3 MaxConsecutiveRollbackException (com.sun.messaging.jmq.jmsserver.util.MaxConsecutiveRollbackException)3