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");
}
}
}
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;
}
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;
}
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));
}
}
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;
}
Aggregations