use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.
the class ProtocolImpl method prepareTransaction.
/**
* prepare a transaction.
*
* @param id The TransactionUID to prepare
*/
@Override
public void prepareTransaction(TransactionUID id, IMQConnection con) throws BrokerException {
if (DEBUG) {
logger.log(Logger.INFO, "ProtocolImpl.PREPARE TRANSACTION:TID=" + id + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "]");
}
TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
if (oo == null) {
throw new BrokerException("Unknown transaction id " + id, Status.NOT_FOUND);
}
TransactionList tl = (TransactionList) oo[0];
TransactionState ts = (TransactionState) oo[1];
handler.doPrepare(tl, id, null, /* xaFlags */
ts, PacketType.PREPARE_TRANSACTION, con);
}
use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.
the class ProtocolImpl method endTransaction.
/**
* End a transaction.
*
* @param id The TransactionUID to end
* @param xid The Xid of the transaction to end. Required if transaction is an XA transaction. Must be null if it is not
* an XA transaction.
* @param xaFlags xaFlags passed on END operation. Used only if an XA transaction.
*/
@Override
public void endTransaction(TransactionUID id, JMQXid xid, Integer xaFlags, IMQConnection con) throws BrokerException {
if (DEBUG) {
logger.log(Logger.INFO, "ProtocolImpl.END TRANSACTION:TID=" + id + ", XID=" + xid + ", xaFlags=" + TransactionState.xaFlagToString(xaFlags) + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "]");
}
TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
if (oo == null) {
throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
}
TransactionList tl = (TransactionList) oo[0];
TransactionState ts = (TransactionState) oo[1];
handler.doEnd(tl, PacketType.END_TRANSACTION, xid, xaFlags, ts, id);
}
use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.
the class TransactionManagerConfig method doRollbackCommit.
public void doRollbackCommit(String transactionID, boolean rollback) throws MBeanException {
try {
long longTid = 0;
if (transactionID == null) {
throw new Exception("Null transaction ID");
}
try {
longTid = Long.parseLong(transactionID);
} catch (Exception e) {
throw new Exception("Invalid transaction ID: " + transactionID);
}
TransactionUID tid = new TransactionUID(longTid);
TransactionList[] tls = Globals.getDestinationList().getTransactionList(null);
TransactionList tl = null;
TransactionState ts = null;
for (int i = 0; i < tls.length; i++) {
tl = tls[i];
if (tl == null) {
continue;
}
ts = tl.retrieveState(tid);
if (ts == null) {
continue;
}
break;
}
if (ts == null) {
throw new Exception(rb.getString(rb.E_NO_SUCH_TRANSACTION, tid));
}
if (ts.getState() != TransactionState.PREPARED) {
throw new Exception(rb.getString(rb.E_TRANSACTION_NOT_PREPARED, tid));
}
JMQXid xid = tl.UIDToXid(tid);
if (xid == null) {
throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not find Xid for " + tid));
}
PacketRouter pr = Globals.getPacketRouter(0);
if (pr == null) {
throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not locate Packet Router"));
}
TransactionHandler thandler = (TransactionHandler) pr.getHandler(PacketType.ROLLBACK_TRANSACTION);
if (thandler == null) {
throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR, "Could not locate Transaction Handler"));
}
if (rollback) {
thandler.doRollback(tl, tid, xid, null, ts, null, null, RollbackReason.ADMIN);
} else {
thandler.doCommit(tl, tid, xid, Integer.valueOf(XAResource.TMNOFLAGS), ts, null, false, null, null);
}
} catch (Exception e) {
String opName;
if (rollback) {
opName = TransactionOperations.ROLLBACK;
} else {
opName = TransactionOperations.COMMIT;
}
handleOperationException(opName, e);
}
}
use of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler in project openmq by eclipse-ee4j.
the class IMQConnection method cleanUpTransactions.
private synchronized void cleanUpTransactions() {
logger.log(Logger.DEBUG, "Cleaning up transactions on connection " + this);
List conlist = (List) getClientData(TRANSACTION_LIST);
if (conlist != null) {
boolean xaretainall = Globals.getConfig().getBooleanProperty(TransactionList.XA_TXN_DETACHED_RETAINALL_PROP, false);
ArrayList timeoutTIDs = new ArrayList();
TransactionUID tid = null;
boolean xaretainallLogged = false;
TransactionHandler rollbackHandler = (TransactionHandler) Globals.getPacketRouter(0).getHandler(PacketType.ROLLBACK_TRANSACTION);
TransactionList[] tls = Globals.getDestinationList().getTransactionList(pstore);
TransactionList tl = tls[0];
TransactionUID[] tuids = (TransactionUID[]) conlist.toArray(new TransactionUID[conlist.size()]);
for (int i = 0; i < tuids.length; i++) {
tid = tuids[i];
TransactionState ts = tl.retrieveState(tid);
if (ts == null) {
// nothing to do if no transaction state
continue;
}
int tstate = ts.getState();
if (tstate == TransactionState.PREPARED && ts.getOnephasePrepare()) {
ts.detachedFromConnection();
timeoutTIDs.add(tid);
String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate) + "[onephase=true]", getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
if (ts.getXid() != null) {
if (xaretainall) {
if (!xaretainallLogged) {
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_RETAIN_XA));
xaretainallLogged = true;
}
continue;
}
if (tstate > TransactionState.COMPLETE) {
String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate), getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
if (tstate == TransactionState.INCOMPLETE || tstate == TransactionState.COMPLETE) {
ts.detachedFromConnection();
timeoutTIDs.add(tid);
String[] args = { "" + tid + "(XID=" + ts.getXid() + ")", TransactionState.toString(tstate), getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
}
if (tstate == TransactionState.PREPARED || tstate == TransactionState.COMMITTED || tstate == TransactionState.ROLLEDBACK) {
String[] args = { "" + tid, TransactionState.toString(tstate), getConnectionUID().toString() };
logger.log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
continue;
}
if (DEBUG || DEBUG_TXN) {
logger.log(Logger.INFO, "Cleanup connection [" + getConnectionUID() + "]: cleaning up transaction " + tid + "[" + TransactionState.toString(tstate) + "]");
}
try {
rollbackHandler.doRollback(tl, tid, ts.getXid(), null, ts, conlist, null, RollbackReason.CONNECTION_CLEANUP);
} catch (Exception e) {
String[] args = { "" + tid + "[" + TransactionState.toString(tstate) + "]", getConnectionUID().toString(), e.getMessage() };
logger.logStack(logger.WARNING, Globals.getBrokerResources().getString(BrokerResources.W_CONN_CLEANUP_ROLLBACK_TRAN_FAIL, args), e);
}
}
Iterator itr = timeoutTIDs.iterator();
while (itr.hasNext()) {
tid = (TransactionUID) itr.next();
tl.addDetachedTransactionID(tid);
}
timeoutTIDs.clear();
conlist.clear();
}
}
Aggregations