use of com.sun.messaging.jmq.jmsserver.data.TransactionState in project openmq by eclipse-ee4j.
the class TidList method storeClusterTransaction.
/**
* Store a cluster transaction.
*
* @param id the id of the transaction to be persisted
* @param ts the transaction's state to be persisted
* @param brokers the transaction's participant brokers
* @exception BrokerException if an error occurs while persisting or the same transaction id exists the store already
* @exception NullPointerException if <code>id</code> is <code>null</code>
*/
public void storeClusterTransaction(TransactionUID id, TransactionState ts, TransactionBroker[] brokers, boolean sync) throws BrokerException {
TransactionInfo txnInfo = null;
try {
// TransactionState is mutable, so we must store a copy
// See bug 4989708
txnInfo = new TransactionInfo(new TransactionState(ts), null, brokers, TransactionInfo.TXN_CLUSTER);
Object oldValue = tidMap.putIfAbsent(id, txnInfo);
if (oldValue != null) {
logger.log(Logger.ERROR, BrokerResources.E_TRANSACTIONID_EXISTS_IN_STORE, id);
throw new BrokerException(br.getString(BrokerResources.E_TRANSACTIONID_EXISTS_IN_STORE, id));
}
if (sync) {
sync(id);
}
} catch (RuntimeException e) {
String msg = (txnInfo != null) ? id + " " + txnInfo : id.toString();
logger.log(Logger.ERROR, BrokerResources.X_PERSIST_TRANSACTION_FAILED, msg, e);
throw new BrokerException(br.getString(BrokerResources.X_PERSIST_TRANSACTION_FAILED, msg), e);
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionState in project openmq by eclipse-ee4j.
the class TidList method loadClientDataOldFormat.
private void loadClientDataOldFormat() throws PHashMapLoadException {
if (!updateOptimization) {
// nothing to do
return;
}
PHashMapLoadException loadException = null;
Iterator itr = tidMap.entrySet().iterator();
while (itr.hasNext()) {
Throwable ex = null;
Map.Entry entry = (Map.Entry) itr.next();
Object key = entry.getKey();
TransactionState value = (TransactionState) entry.getValue();
byte[] cData = null;
try {
cData = ((PHashMapMMF) tidMap).getClientData(key);
if (cData != null && cData.length > 0) {
// 1st byte is the modified state
int state = cData[0];
// update txn state
value.setState(state);
}
} catch (Throwable e) {
ex = e;
}
if (ex != null) {
PHashMapLoadException le = new PHashMapLoadException("Failed to load client data [cData=" + Arrays.toString(cData) + "]");
le.setKey(key);
le.setValue(value);
le.setNextException(loadException);
le.initCause(ex);
loadException = le;
}
}
if (loadException != null) {
throw loadException;
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionState in project openmq by eclipse-ee4j.
the class AckHandler method handleTransaction.
public void handleTransaction(TransactionList translist, IMQConnection con, TransactionUID tid, SysMessageID[] ids, ConsumerUID[] cids, int deliverCnt) throws BrokerException {
for (int i = 0; i < ids.length; i++) {
Consumer consumer = null;
try {
// lookup the session by consumerUID
Session s = Session.getSession(cids[i]);
// look up the consumer by consumerUID
consumer = Consumer.getConsumer(cids[i]);
if (consumer == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.I_ACK_FAILED_NO_CONSUMER, cids[i]) + "[TID=" + tid + "]", Status.NOT_FOUND);
}
// try and find the stored consumerUID
ConsumerUID sid = consumer.getStoredConsumerUID();
// if we still dont have a session, attempt to find one
if (s == null) {
SessionUID suid = consumer.getSessionUID();
s = Session.getSession(suid);
}
if (s == null) {
if (BrokerStateHandler.isShutdownStarted()) {
throw new BrokerException(BrokerResources.I_ACK_FAILED_BROKER_SHUTDOWN);
}
throw new BrokerException(br.getKString(br.I_ACK_FAILED_NO_SESSION, "[" + ids[i] + ", " + cids[i] + "]TID=" + tid));
}
if (DEBUG) {
logger.log(logger.INFO, "handleTransaction.addAck[" + i + ", " + ids.length + "]:tid=" + tid + ", sysid=" + ids[i] + ", cid=" + cids[i] + ", sid=" + sid + " on connection " + con);
}
boolean isxa = translist.addAcknowledgement(tid, ids[i], cids[i], sid);
BrokerAddress addr = (BrokerAddress) s.ackInTransaction(cids[i], ids[i], tid, isxa, deliverCnt);
if (addr != null && addr != Globals.getMyAddress()) {
translist.setAckBrokerAddress(tid, ids[i], cids[i], addr);
}
if (fi.FAULT_INJECTION) {
if (fi.checkFault(fi.FAULT_TXN_ACK_1_5, null)) {
fi.unsetFault(fi.FAULT_TXN_ACK_1_5);
TransactionAckExistException tae = new TransactionAckExistException("FAULT:" + fi.FAULT_TXN_ACK_1_5, Status.GONE);
tae.setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
tae.setRemote(true);
consumer.recreationRequested();
throw tae;
}
}
} catch (Exception ex) {
String emsg = "[" + ids[i] + ", " + cids[i] + "]TUID=" + tid;
if ((ex instanceof BrokerException) && ((BrokerException) ex).getStatusCode() != Status.ERROR) {
logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
} else {
logger.log(Logger.ERROR, Globals.getBrokerResources().getKString(BrokerResources.E_TRAN_ACK_PROCESSING_FAILED, emsg, ex.getMessage()), ex);
}
int state = -1;
JMQXid xid = null;
try {
TransactionState ts = translist.retrieveState(tid);
if (ts != null) {
state = ts.getState();
xid = ts.getXid();
}
translist.updateState(tid, TransactionState.FAILED, true);
} catch (Exception e) {
if (!(e instanceof UnknownTransactionException)) {
String[] args = { TransactionState.toString(state), TransactionState.toString(TransactionState.FAILED), tid.toString(), (xid == null ? "null" : xid.toString()) };
logger.log(Logger.WARNING, Globals.getBrokerResources().getKString(BrokerResources.W_UPDATE_TRAN_STATE_FAIL, args));
}
}
if (ex instanceof TransactionAckExistException) {
PacketReference ref = DL.get(null, ids[i]);
if (ref != null && (ref.isOverrided() || ref.isOverriding())) {
((BrokerException) ex).overrideStatusCode(Status.GONE);
((BrokerException) ex).setRemoteConsumerUIDs(String.valueOf(cids[i].longValue()));
((BrokerException) ex).setRemote(true);
consumer.recreationRequested();
}
}
if (ex instanceof BrokerException) {
throw (BrokerException) ex;
}
throw new BrokerException("Internal Error: Unable to " + " complete processing acknowledgements in a tranaction: " + ex, ex);
}
}
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionState in project openmq by eclipse-ee4j.
the class QBrowseHandler method getQBrowseList.
public ArrayList getQBrowseList(Destination d, String selectorstr) throws BrokerException, SelectorFormatException {
Collection msgs = null;
if (selectorstr == null) {
msgs = d.getAll((Filter) null).values();
} else {
SelectorFilter f = new SelectorFilter(selectorstr);
Map m = d.getAll(f);
msgs = m.values();
}
// sort the messages
ArrayList sorted = new ArrayList(msgs);
Collections.sort(sorted, new RefCompare());
TransactionList[] tls = DL.getTransactionList(d.getPartitionedStore());
TransactionList tlist = tls[0];
// remove any expired messages or messages in open txn
Iterator itr = sorted.iterator();
while (itr.hasNext()) {
PacketReference p = (PacketReference) itr.next();
if (p.isExpired()) {
itr.remove();
}
if (!p.isDeliveryDue()) {
itr.remove();
}
if (p.getTransactionID() != null) {
// look up txn
TransactionState ts = tlist.retrieveState(p.getTransactionID());
if (ts != null && ts.getState() != TransactionState.COMMITTED) {
// open txn, remove
itr.remove();
}
}
// check in takeover processing
if (p.checkLock(false) == null) {
itr.remove();
}
}
ArrayList returnmsgs = new ArrayList();
itr = sorted.iterator();
while (itr.hasNext()) {
PacketReference p = (PacketReference) itr.next();
if (p == null) {
continue;
}
returnmsgs.add(p.getSysMessageID());
}
return returnmsgs;
}
use of com.sun.messaging.jmq.jmsserver.data.TransactionState in project openmq by eclipse-ee4j.
the class TransactionHandler method doPrepare.
public BaseTransaction doPrepare(TransactionList translist, TransactionUID id, Integer xaFlags, TransactionState ts, int pktType, boolean onephasePrepare, TransactionWork txnWork, IMQConnection con) throws BrokerException {
BaseTransaction baseTransaction = null;
boolean persist = true;
PartitionedStore pstore = translist.getPartitionedStore();
if (Globals.isNewTxnLogEnabled()) {
// don't persist transaction state as we are logging it instead
persist = false;
if (txnWork == null) {
// prepare has been called directly from an end client
// We need to construct the transactional work
List plist = translist.retrieveSentMessages(id);
HashMap cmap = translist.retrieveConsumedMessages(id);
HashMap sToCmap = translist.retrieveStoredConsumerUIDs(id);
txnWork = getTransactionWork2(pstore, plist, cmap, sToCmap);
}
}
boolean prepared = false;
int s = ts.nextState(pktType, xaFlags);
try {
TransactionState nextState = new TransactionState(ts);
nextState.setState(s);
nextState.setOnephasePrepare(true);
baseTransaction = doRemotePrepare(translist, id, nextState, txnWork);
if (baseTransaction == null) {
// The end client must have called prepare
if (Globals.isNewTxnLogEnabled()) {
baseTransaction = new LocalTransaction();
baseTransaction.setTransactionWork(txnWork);
baseTransaction.setTransactionState(nextState);
baseTransaction.getTransactionDetails().setTid(id);
baseTransaction.getTransactionDetails().setXid(ts.getXid());
baseTransaction.getTransactionDetails().setState(TransactionState.PREPARED);
logTxn(pstore, baseTransaction);
}
}
if (ts.getType() != AutoRollbackType.NEVER && Globals.isMinimumPersistLevel2()) {
translist.updateStatePrepareWithWork(id, s, onephasePrepare, persist);
} else {
translist.updateState(id, s, onephasePrepare, persist);
}
prepared = true;
if (fi.FAULT_INJECTION) {
if (fi.checkFault(fi.FAULT_TXN_PREPARE_3_KILL_CLIENT, null)) {
fi.unsetFault(fi.FAULT_TXN_PREPARE_3_KILL_CLIENT);
Properties p = new Properties();
p.setProperty("kill.jvm", "true");
try {
DebugHandler.sendClientDEBUG(con, (new Hashtable()), p);
} catch (IOException e) {
logger.log(logger.WARNING, "TransactionHandler: Unable to sendClientDEBUG: e.toString()");
}
} else if (fi.checkFault(fi.FAULT_TXN_PREPARE_3_CLOSE_CLIENT, null)) {
fi.unsetFault(fi.FAULT_TXN_PREPARE_3_CLOSE_CLIENT);
Properties p = new Properties();
p.setProperty("close.conn", "true");
try {
DebugHandler.sendClientDEBUG(con, (new Hashtable()), p);
} catch (IOException e) {
logger.log(logger.WARNING, "TransactionHandler: Unable to sendClientDEBUG: e.toString()");
}
}
fi.checkFaultAndExit(FaultInjection.FAULT_TXN_PREPARE_2_0, null, 2, false);
}
try {
Agent agent = Globals.getAgent();
if (agent != null) {
agent.notifyTransactionPrepare(id);
}
} catch (Throwable t) {
logger.log(Logger.WARNING, "XXXI18N - JMX agent notify transaction prepared failed: " + t.getMessage());
}
} finally {
if (!prepared) {
translist.updateState(id, TransactionState.FAILED, onephasePrepare, TransactionState.PREPARED, persist);
}
}
return baseTransaction;
}
Aggregations