use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.
the class RaptorProtocol method sendTransactionInquiry.
/**
* Caller must ensure broker is the transaction home broker
*/
@Override
public void sendTransactionInquiry(TransactionUID tid, BrokerAddress broker) {
TransactionBroker tb = new TransactionBroker(broker);
BrokerAddress to = tb.getCurrentBrokerAddress();
ClusterTxnInquiryInfo cii = ClusterTxnInquiryInfo.newInstance(Long.valueOf(tid.longValue()), to, null);
if (DEBUG_CLUSTER_TXN) {
logger.log(Logger.INFO, "Sending transaction inquiry: " + cii + " to " + to + "[" + broker + "]");
}
try {
c.unicast(to, cii.getGPacket());
} catch (Exception e) {
logger.log(Logger.WARNING, "Sending transaction inquiry " + cii + " to " + to + "[" + broker + "] failed");
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.
the class RaptorProtocol method receivedTransactionInquiry.
public void receivedTransactionInquiry(GPacket pkt, BrokerAddress from) {
ClusterTxnInquiryInfo cii = ClusterTxnInquiryInfo.newInstance(pkt);
if (DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "Received transaction inquiry " + cii.toString() + " from " + from);
}
TransactionUID tid = new TransactionUID(cii.getTransactionID().longValue());
BrokerAddress txnHomeBroker = cii.getTransactionHome();
TransactionBroker thb = null;
if (txnHomeBroker != null) {
thb = new TransactionBroker(txnHomeBroker);
}
Object[] oo = TransactionList.getTransListAndState(tid, null, true, false);
TransactionState ts = null;
if (oo != null) {
// tl = (TransactionList)oo[0];
ts = (TransactionState) oo[1];
}
if (ts == null && DEBUG_CLUSTER_TXN) {
logger.log(logger.INFO, "Transaction " + tid + " not found in local transactions");
}
if (ts != null) {
BrokerAddress currba = (thb == null ? null : thb.getCurrentBrokerAddress());
if (currba != null && !currba.equals(Globals.getMyAddress())) {
logger.log(logger.INFO, "Transaction " + tid + " home broker current address " + currba + ", old address " + txnHomeBroker + " inquired from " + from);
}
sendClusterTransactionInfo(tid, from, cii.getXid());
return;
}
if (thb != null) {
BrokerAddress currba = thb.getCurrentBrokerAddress();
if (currba != null && Globals.getMyAddress().equals(currba)) {
sendClusterTransactionInfo(tid, from, cii.getXid());
return;
}
}
sendRemoteTransactionInfo(tid, from, cii.getXid(), false);
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.
the class ClusterTransaction2PPrepareEvent method readFromBytes.
@Override
public void readFromBytes(byte[] data) throws IOException, BrokerException {
if (Store.getDEBUG()) {
Globals.getLogger().log(Logger.DEBUG, getPrefix() + "readFromBytes");
}
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
clusterTransaction = new ClusterTransaction();
dis.skip(2);
clusterTransaction.getTransactionDetails().readContent(dis);
if (Store.getDEBUG()) {
Globals.getLogger().log(Logger.DEBUG, getPrefix() + "read details " + clusterTransaction.getTransactionDetails());
}
TransactionWork work = new TransactionWork();
work.readWork(dis);
clusterTransaction.setTransactionWork(work);
int objectBodySize = dis.readInt();
byte[] objectBody = new byte[objectBodySize];
dis.read(objectBody);
ByteArrayInputStream bais2 = new ByteArrayInputStream(objectBody);
ObjectInputStream ois = new FilteringObjectInputStream(bais2);
try {
clusterTransaction.setTransactionState((TransactionState) ois.readObject());
clusterTransaction.setTransactionBrokers((TransactionBroker[]) ois.readObject());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ois.close();
bais2.close();
dis.close();
bais.close();
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.
the class TransactionDAOImpl method updateTransactionBrokerState.
/**
* Update transaction's participant broker state if the txn's state matches the expected state.
*
* @param conn database connection
* @param txnUID the transaction ID
* @param expectedTxnState the expected transaction state
* @param txnBkr the participant broker to be updated
* @throws BrokerException if transaction does not exists in the store
*/
@Override
public void updateTransactionBrokerState(Connection conn, TransactionUID txnUID, int expectedTxnState, TransactionBroker txnBkr) throws BrokerException {
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(false);
myConn = true;
}
// First, retrieve the TransactionBroker array
int state;
TransactionBroker[] txnBrokers;
pstmt = dbMgr.createPreparedStatement(conn, selectTxnBrokersSQL);
pstmt.setLong(1, id);
rs = pstmt.executeQuery();
if (rs.next()) {
txnBrokers = (TransactionBroker[]) Util.readObject(rs, 1);
state = rs.getInt(2);
} else {
throw new BrokerException(br.getKString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, txnUID), Status.NOT_FOUND);
}
if (state != expectedTxnState) {
Object[] args = { txnBkr, txnUID, TransactionState.toString(expectedTxnState), TransactionState.toString(state) };
throw new BrokerException(br.getKString(BrokerResources.E_UPDATE_TXNBROKER_FAILED, args), Status.CONFLICT);
}
// Update the participant broker state
for (int i = 0, len = txnBrokers.length; i < len; i++) {
TransactionBroker bkr = txnBrokers[i];
if (bkr.equals(txnBkr)) {
bkr.copyState(txnBkr);
// done
break;
}
}
// Now update the DB entry
updateTransactionBrokers(conn, txnUID, txnBrokers);
// Commit all changes
if (myConn) {
conn.commit();
}
} 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 IOException) {
ex = DBManager.wrapIOException("[" + selectTxnBrokersSQL + "]", (IOException) e);
} else if (e instanceof SQLException) {
ex = DBManager.wrapSQLException("[" + selectTxnBrokersSQL + "]", (SQLException) e);
} else {
ex = e;
}
BrokerException be = new BrokerException(br.getKString(BrokerResources.X_PERSIST_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);
}
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionBroker in project openmq by eclipse-ee4j.
the class TransactionDAOImpl method getTransactionStatesByBroker.
/**
* Retrieve all local and cluster transaction states.
*
* @param conn database connection
* @param brokerID the broker ID
* @return a Map of transaction IDs and TransactionState objects; an empty Map is returned if no transactions exist in
* the store
*/
@Override
public HashMap getTransactionStatesByBroker(Connection conn, String brokerID, Long storeSession) throws BrokerException {
HashMap map = new HashMap();
boolean myConn = false;
PreparedStatement pstmt = null;
ResultSet rs = null;
Exception myex = null;
String sql = selectTxnStatesByBrokerSQL;
try {
// Get a connection
DBManager dbMgr = DBManager.getDBManager();
if (conn == null) {
conn = dbMgr.getConnection(true);
myConn = true;
}
if (brokerID == null) {
brokerID = dbMgr.getBrokerID();
}
if (storeSession != null) {
StoreSessionDAOImpl.checkStoreSessionOwner(conn, storeSession, brokerID);
sql = selectTxnStatesBySessionSQL;
}
pstmt = dbMgr.createPreparedStatement(conn, sql);
if (storeSession != null) {
pstmt.setLong(1, storeSession.longValue());
} else {
pstmt.setString(1, brokerID);
}
rs = pstmt.executeQuery();
while (rs.next()) {
try {
long id = rs.getLong(1);
int type = rs.getInt(2);
int state = rs.getInt(3);
TransactionState txnState = (TransactionState) Util.readObject(rs, 4);
txnState.setState(state);
TransactionBroker[] txnBrokers = (TransactionBroker[]) Util.readObject(rs, 5);
map.put(new TransactionUID(id), new TransactionInfo(txnState, null, txnBrokers, type));
} catch (IOException e) {
// fail to parse TransactionState object; just log it
logger.logStack(Logger.ERROR, BrokerResources.X_PARSE_TRANSACTION_FAILED, e);
}
}
} 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("[" + sql + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(BrokerResources.X_LOAD_TRANSACTIONS_FAILED), ex);
} finally {
if (myConn) {
Util.close(rs, pstmt, conn, myex);
} else {
Util.close(rs, pstmt, null, myex);
}
}
return map;
}
Aggregations