use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.
the class TransactionWorkInfo method getMessage.
/**
* Return the message. The message is only cached when it is loaded from the backing buffer the first time. It will be
* set to null after it is retrieved. From then on, we always read it from the backing buffer again.
*/
synchronized BaseTransaction getMessage() throws IOException {
if (msg == null) {
if (vrecord != null) {
// read from backing buffer
try {
return parseTransactionWork(vrecord);
} catch (IOException e) {
logger.log(logger.ERROR, parent.storeName + ":failed to parse message from vrecord(" + vrecord + ")", e);
throw e;
}
} else {
try {
byte[] data = parent.loadData(tid);
return parseTransactionWork(data);
} catch (IOException e) {
logger.log(logger.ERROR, parent.storeName + ":failed to parse message from byte array", e);
throw e;
}
}
} else {
BaseTransaction pkt = msg;
msg = null;
return pkt;
}
}
use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.
the class ClusterTransactionManager method replayTransactionEvent.
@Override
void replayTransactionEvent(TransactionEvent txnEvent, HashSet dstLoadedSet) throws BrokerException, IOException {
if (Store.getDEBUG()) {
Globals.getLogger().log(Logger.DEBUG, getPrefix() + " replayTransactionEvent");
}
ClusterTransactionEvent clusterTxnEvent = (ClusterTransactionEvent) txnEvent;
// replay to store on commit
ClusterTransaction clusterTxn = clusterTxnEvent.clusterTransaction;
int state = clusterTxn.getState();
TransactionUID tid = clusterTxn.getTid();
if (clusterTxnEvent.getSubType() == ClusterTransactionEvent.Type2PPrepareEvent) {
// in prepared txn store and resetting the transaction log
if (incompleteStored.containsKey(tid)) {
if (Store.getDEBUG()) {
String msg = getPrefix() + " found matching txn in prepared store on replay " + clusterTxn;
Globals.getLogger().log(Logger.DEBUG, msg);
}
} else {
addToIncompleteUnstored(clusterTxn);
}
} else if (clusterTxnEvent.getSubType() == ClusterTransactionEvent.Type2PCompleteEvent) {
// we are completing a transaction
// the transaction could be
// a) unstored (prepare replayed earlier)
// b) stored incomplete (prepare occurred before last checkpoint,
// completion not written to prepared store yet)
// This should therefore be the last entry in log.
// c) stored complete (prepare occurred before last checkpoint,
// and failure occurred after completion stored in prepared store
BaseTransaction existingWork = null;
if (incompleteUnstored.containsKey(tid)) {
// a) unstored (prepare replayed earlier)
if (state == TransactionState.ROLLEDBACK) {
existingWork = removeFromIncompleteUnstored(tid);
} else if (state == TransactionState.COMMITTED) {
existingWork = incompleteUnstored.get(tid);
existingWork.getTransactionDetails().setState(state);
existingWork.getTransactionState().setState(state);
}
} else if (incompleteStored.containsKey(tid)) {
// b) stored incomplete (prepare occurred before last checkpoint,
// completion not written to prepared store yet)
existingWork = removeFromIncompleteStored(tid);
updateStoredState(tid, state);
addToCompleteStored(existingWork);
} else if (completeStored.containsKey(tid)) {
// c) stored complete (prepare occurred before last checkpoint,
// and failure occurred after completion stored in prepared store
existingWork = completeStored.get(tid);
}
if (existingWork != null) {
if (state == TransactionState.COMMITTED) {
transactionLogManager.transactionLogReplayer.replayTransactionWork(existingWork.getTransactionWork(), tid, dstLoadedSet);
}
} else {
logger.log(Logger.ERROR, "Could not find prepared work for completing two-phase transaction " + clusterTxn.getTid());
}
}
}
use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.
the class LocalTransactionManager method replayTransactionEvent.
@Override
void replayTransactionEvent(TransactionEvent txnEvent, HashSet dstLoadedSet) throws BrokerException, IOException {
if (Store.getDEBUG()) {
Globals.getLogger().log(Logger.DEBUG, getPrefix() + " replayTransactionEvent");
}
LocalTransactionEvent localTxnEvent = (LocalTransactionEvent) txnEvent;
// replay to store on commit
LocalTransaction localTxn = localTxnEvent.localTransaction;
int state = localTxn.getState();
TransactionUID tid = localTxn.getTid();
if (localTxnEvent.getSubType() == LocalTransactionEvent.Type1PCommitEvent) {
// one phase commit
// Just replay it now
transactionLogManager.transactionLogReplayer.replayTransactionWork(localTxn.getTransactionWork(), tid, dstLoadedSet);
} else if (localTxnEvent.getSubType() == LocalTransactionEvent.Type2PPrepareEvent) {
// in prepared txn store and resetting the transaction log
if (incompleteStored.containsKey(tid)) {
if (Store.getDEBUG()) {
String msg = getPrefix() + " found matching txn in prepared store on replay " + localTxn;
Globals.getLogger().log(Logger.DEBUG, msg);
}
} else {
addToIncompleteUnstored(localTxn);
}
} else if (localTxnEvent.getSubType() == LocalTransactionEvent.Type2PCompleteEvent) {
// we are completing a transaction
// the transaction could be
// a) unstored (prepare replayed earlier)
// b) stored incomplete (prepare occurred before last checkpoint,
// completion not written to prepared store yet)
// This should therefore be the last entry in log.
// c) stored complete (prepare occurred before last checkpoint,
// and failure occurred after completion stored in prepared store
BaseTransaction existingWork = null;
if (incompleteUnstored.containsKey(tid)) {
// a) unstored (prepare replayed earlier)
existingWork = removeFromIncompleteUnstored(tid);
} else if (incompleteStored.containsKey(tid)) {
// b) stored incomplete (prepare occurred before last checkpoint,
// completion not written to prepared store yet)
existingWork = removeFromIncompleteStored(tid);
updateStoredState(tid, state);
addToCompleteStored(existingWork);
} else if (completeStored.containsKey(tid)) {
// c) stored complete (prepare occurred before last checkpoint,
// and failure occurred after completion stored in prepared store
existingWork = completeStored.get(tid);
}
if (existingWork != null) {
if (state == TransactionState.COMMITTED) {
transactionLogManager.transactionLogReplayer.replayTransactionWork(existingWork.getTransactionWork(), tid, dstLoadedSet);
}
} else {
logger.log(Logger.ERROR, "Could not find prepared work for completing two-phase transaction " + localTxn.getTid());
}
}
}
use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.
the class BaseTransactionManager method getAllTransactionsMap.
public HashMap getAllTransactionsMap() {
List<BaseTransaction> txns = getAllIncompleteTransactions();
HashMap map = new HashMap(txns.size());
Iterator<BaseTransaction> itr = txns.iterator();
while (itr.hasNext()) {
BaseTransaction txn = itr.next();
TransactionState txnState = new TransactionState(txn.getTransactionState());
map.put(txn.getTid(), txnState);
}
return map;
}
use of com.sun.messaging.jmq.jmsserver.data.BaseTransaction in project openmq by eclipse-ee4j.
the class BaseTransactionManager method processTxnCompletion.
BaseTransaction processTxnCompletion(TransactionUID tid, int state, boolean fullyComplete) throws IOException, BrokerException {
// If it is mark it as committed, so that it can be cleaned up after next checkpoint
if (state == TransactionState.COMMITTED) {
this.playingToMessageStore.add(tid);
if (Store.getDEBUG()) {
String msg = getPrefix() + " add transaction to playingToMessageStore." + " tid=" + tid + " size = " + playingToMessageStore.size();
logger.log(Logger.DEBUG, msg);
}
}
BaseTransaction existingTxn = null;
boolean stored = false;
existingTxn = incompleteUnstored.get(tid);
if (existingTxn == null) {
existingTxn = incompleteStored.get(tid);
if (existingTxn != null) {
stored = true;
} else {
String msg = getPrefix() + " processTxnCompletion: Could not find txn for " + tid;
logger.log(Logger.WARNING, msg);
throw new BrokerException(msg);
}
}
existingTxn.getTransactionDetails().setState(state);
if (stored) {
// update the stored transaction from prepared to committed/rolledback state
// update state on file by writing at fixed offset
updateStoredState(tid, state);
if (fullyComplete) {
incompleteStored.remove(tid);
completeStored.put(tid, existingTxn);
}
} else {
if (fullyComplete) {
removeFromIncompleteUnstored(tid);
}
}
messageListLogged(existingTxn);
return existingTxn;
}
Aggregations